PHP Regex for image

suklee

Diamond Member
Oct 9, 1999
4,575
10
81
Am trying to get the SRC attribute of a IMG tag. This works, except when there is a space in the filename. See this URL.. (copy and paste into browser)

This is the pattern I am using. How do I allow for the possibility of a space in the filename?

/src=[\'"]?([^\'" >]+)[\'" >]/


 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
You're allowing for the possibility that the URL won't be quote-delimited? If so, then there doesn't seem to be a good way, unless you want to specify that if there is a space then the URL must be quote delimited. If you don't want to do that, you could search for .jpg/.gif/.png/etc., though this isn't a failproof solution.
 

Titan

Golden Member
Oct 15, 1999
1,819
0
0
Are you prohibited from using Javascript for some reason? If not use Javascript, either to send it to PHP through a form, or do whatever you want (maybe via ajax?) when rendering the page.