Forum Moderators: coopster
http://10.10.10.10/media/image.asp?id=61169&img=77_9_59_38-PMsomeimagename.jpg&w=640&h=480&client_id=989 Ok gurus. I figured I should be using Regex with a preg_match to pull out the image url but cannot find the right solution.
I need to get the "77_9_59_38-PMsomeimagename.jpg" out of the url, essentially, parsing everything between the "img=" and the "&w=" I have a bunch of these in an xml file I am parsing. I can download the file ok, but unless I can grab the filename out of the url, I have to make my own filename and I cannot always assume it is a JPG. By pulling the filename value and extension out, I can download the file and save it using the original filename.
It would extra special if I could grab the filename and extension separatedly in regex but I always explode it and grab the values from the array.
What is the best way to do this? The image name could contain any combination of numbers, letters, underscores and dashes in any case...
Thanks for any help you can be!
So for instance the pattern: [^.]+ captures 1 or more of anything that is not a period. When a period is reached the matching stops. Putting it in parenthesis ([^.]+) causes it to be saved as a sub pattern match.