skwap Posted December 30, 2011 Share Posted December 30, 2011 Hello Dear, i want to get the text value (bla bla bla) from the below string. $string = "<div class="on"> <p>bla bla bla</p></div>"; my code is $desc_pattern = '/\<div class=\"on\"><p>(.*)<\/p><\/div>/s'; preg_match($desc_pattern,$string,$new_desc); print_r($new_desc); but its only showing Array ( ) please help me Link to comment https://forums.phpfreaks.com/topic/254067-preg_match-not-working/ Share on other sites More sharing options...
The Little Guy Posted December 30, 2011 Share Posted December 30, 2011 because your string has a space between your opening div/p, but your regular expression doesn't allow for that. Link to comment https://forums.phpfreaks.com/topic/254067-preg_match-not-working/#findComment-1302462 Share on other sites More sharing options...
skwap Posted December 30, 2011 Author Share Posted December 30, 2011 Then what can i do ?? can you please help me Link to comment https://forums.phpfreaks.com/topic/254067-preg_match-not-working/#findComment-1302463 Share on other sites More sharing options...
The Little Guy Posted December 30, 2011 Share Posted December 30, 2011 You could choose one of these patterns: $desc_pattern = '/\<div class=\"on\">.*<p>(.*)<\/p><\/div>/s'; $desc_pattern = '/\<div class=\"on\"> <p>(.*)<\/p><\/div>/s'; Link to comment https://forums.phpfreaks.com/topic/254067-preg_match-not-working/#findComment-1302465 Share on other sites More sharing options...
skwap Posted December 30, 2011 Author Share Posted December 30, 2011 not working... actually the source code is <div class="on"> <p>There is a dream car for you. <br> <br>Try the free version of Asphalt 5 and race with the fastest dream cars ever created by some of the most prestigious manufacturers in the world. <br>Everything you’ve ever dreamed of doing behind the wheel is here! <br>Stop dreaming and get in!</p> </div> conside the above is as string & make a pattern Link to comment https://forums.phpfreaks.com/topic/254067-preg_match-not-working/#findComment-1302466 Share on other sites More sharing options...
sandeep529 Posted December 30, 2011 Share Posted December 30, 2011 May be you should use the miltiline modifier http://php.net/manual/en/reference.pcre.pattern.modifiers.php. So your regex becomes $desc_pattern = '/\<div class=\"on\">.*<p>(.*)<\/p><\/div>/sm'; Link to comment https://forums.phpfreaks.com/topic/254067-preg_match-not-working/#findComment-1302469 Share on other sites More sharing options...
The Little Guy Posted December 30, 2011 Share Posted December 30, 2011 I would do these modifiers: $desc_pattern = '/\<div class=\"on\">.*<p>(.*)<\/p><\/div>/isU'; Link to comment https://forums.phpfreaks.com/topic/254067-preg_match-not-working/#findComment-1302587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.