How to replace spaces with %20 in <img> tags
问题 I would like to replace all spaces in the image tags of a html text. Example: <img src="photo 1.jpg" /> to <img src="photo%201.jpg"/> I didn't find a soultion with preg_replace, but it may be a simple regexp line. Thanks! Edit : Sorry guys, my description was not very clear. So, I have a full html page and I only want to replace inside the img tags. I can't use urlencode here as it encodes the other stuff as well. 回答1: The space is represented by a %20 in the url but there are other chars