php - delete only first slashes from url/string
829
I want to delete the first two slashes of my string.
//cdn.klingel.de/images/100/3/7/1/5/0/8/371508F1.jpg
After that I want to include thehttp://
new. But that isn't the problem.
str_replace
replace all slashes...
Info:
I've different strings. Examples:
/media/images/CmsPageModuleDataItem/62/6260.0_gefro-suppennudeln.jpg
//cdn.abc.de/images/100/3/7/1/5/0/8/371508F1.jpg
http://s7.abc.com/is/image/LandsEnd/461469_FG16_LF_616
I need a correcthttp://
in front of these urls.
Maybe someone know a smart solution.
Thank you.
Answer
Solution:
Hope this is this what you are looking for.
gives you
http://Hello World/theEnd!
If you want to get fancy you can put this is a loop as well.
}
this gives you
Answer
Solution:
Another option is to use regex for this:
Here is a regex101 fiddle:
https://regex101.com/r/lUXTDf/1
And this is a usage in php using preg_replace:
http://sandbox.onlinephpfunctions.com/code/b49af5519e8a7a4e47baffa9a8a7199c3bddbd42
Answer
Solution:
A strong way is to use
parse_url
and to rebuild the url part by part:demo
Answer
Solution:
You can use the explode function:
then you can make a forloop to put the array back into a string.
http://www.w3schools.com/php/func_string_explode.asp
Answer
Solution: