I'm trying to match a section of a url up until the & symbol within the url so say the url is www.something.com&src=filename.jpg&size=200 I'm trying to get just the filename.jpg So I try preg_match('/www.something.com&src= (.*) &/'); but it doesn't match it. Is it soemthing to do with the &? I have tried \ it but nothing. Thanks
It basically means, match everything up until you reach &. (.*) would match everything, ignoring the & and continuing to the end of the string. Jay
ok, I understand, but what would define the end of the string with (.*) ? would that mean it would keep searching through the entire page - assuming the url I was matching was within the source of a webpage? Can you recommend anywhere that I can find further reading on the topic as searching google for such things as (.*?) etc brings up anything but relevant results? Thanks a lot
I'm still really stuck with this: I managed to get it to pick something - but in the source code there were several instances of /src=(.*?)&/ Code (markup): and it just returned a single number. So I went back a bit on the url and found enough info to make it unique however parts of this fell on different lines within the source code and I guess this is causing it not to match. So my questions are - what happens if preg_match matches more than one instance within the code and can I limit it to match only the first instance? And is it possible to match data that falls over several lines of source code? Thanks a lot
Use preg_match_all to match more than one, and put 's' after the final / so it becomes /s to match more than one line. Jay
ok, so I can't see where I am going wrong with this /<div id="product-image"><img src="\/resize.php?subject=product&src=(.*?)&w=200/s Code (markup): and here is the source: <div id="product-image"> <img src="/resize.php?subject=product&src=b64db4d4c1108080d0d731782fcd6634.jpg&w=200&h=200&type=thumb-full" Code (markup): and I am trying to get b64db4d4c1108080d0d731782fcd6634.jpg Code (markup): I have tried both & and & Code (markup): and it would seem & is something that at least gets a result Am I being totally stupid here and missing something obvious?
just as an update - I was being stupid in other ways - when I was wiritng the data tot he database I was accidentally restricting it to one character. Thanks for the help anyways but all sorted