lard Posted November 17, 2009 Share Posted November 17, 2009 Hi folks. My question is two fold, firstly I'm trying to use preg_match to strip some data between 2 bits of code. What I have so far is: $string="<p>This is the bit that i want</p><p>I don't want this</p>"; preg_match('/<p>(.+)<\/p>/',$string,$match); $new=$match[1]; echo $new; Which produces This is the bit that i want</p><p>I don't want this How do I make it search for the first instance of </p> rather than the last? I presume that the key lies in the (.+) part, which leads me to my next question. I don't really know what (.+) means (got it from someone else's thread) so it's a struggle to figure it out. Trying to google it is really no help - there are no results, just like with many similar things. Does anyone know of good comprehensive (!!) lists of such things or much better, how to search for info on them. I'm sure google must have covered this somehow but I can't figure it. Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/181855-solved-preg_match-and-googling-code/ Share on other sites More sharing options...
Alex Posted November 17, 2009 Share Posted November 17, 2009 You need to make your regular expression lazy by adding a ?, /<p>(.+?)<\/p>/ Quote Link to comment https://forums.phpfreaks.com/topic/181855-solved-preg_match-and-googling-code/#findComment-959084 Share on other sites More sharing options...
lard Posted November 17, 2009 Author Share Posted November 17, 2009 I knew it'd be simple for someone clever! Thanks chap Quote Link to comment https://forums.phpfreaks.com/topic/181855-solved-preg_match-and-googling-code/#findComment-959097 Share on other sites More sharing options...
MadTechie Posted November 17, 2009 Share Posted November 17, 2009 lard, can you please click "topic solved" to close this thread Quote Link to comment https://forums.phpfreaks.com/topic/181855-solved-preg_match-and-googling-code/#findComment-959103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.