vin_akleh Posted April 8, 2011 Share Posted April 8, 2011 how can i make this work?? i have this variable $title[1] and wanna insert it in the preg_march like so preg_match('/<a href="\/m\/'.$title[1].'_2011\/.*/', $html_poster_link, $poster_link) this doesnt work how can i make it work?? Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/ Share on other sites More sharing options...
BlueSkyIS Posted April 8, 2011 Share Posted April 8, 2011 i think you want preg_replace. http://php.net/manual/en/function.preg-replace.php or if you mean you want $title[1] to be part of the pattern, you're doing it correctly. Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/#findComment-1198949 Share on other sites More sharing options...
vin_akleh Posted April 8, 2011 Author Share Posted April 8, 2011 i do want to pair them but if this realy work then this should work but it doesnt if (preg_match('/<a href="\/m\/'.$title[1].'_2011\/.*/', $html_poster_link, $poster_link)) { ECHO"YES"; } !!! Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/#findComment-1198955 Share on other sites More sharing options...
dcro2 Posted April 8, 2011 Share Posted April 8, 2011 Maybe you can give us a sample to test it on. Are you sure $title[1] contains what you think it contains? Are you sure the code will be in that exact case? (i.e. not <A href=) Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/#findComment-1198957 Share on other sites More sharing options...
vin_akleh Posted April 8, 2011 Author Share Posted April 8, 2011 $html_poster_link = file_get_contents('http://www.rottentomatoes.com/m/hop_2011/'); Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/#findComment-1198959 Share on other sites More sharing options...
dcro2 Posted April 8, 2011 Share Posted April 8, 2011 Works for me, so the problem has to be in $title[1]. Why don't you echo it out to see what it contains? Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/#findComment-1198976 Share on other sites More sharing options...
vin_akleh Posted April 8, 2011 Author Share Posted April 8, 2011 sorry guys but i didn't realize that preg_match was case sensitive Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/#findComment-1199002 Share on other sites More sharing options...
dcro2 Posted April 8, 2011 Share Posted April 8, 2011 Just use this instead (in case you haven't fixed it): if (preg_match('/<a href="\/m\/'.$title[1].'_2011\/.*?/i', $html_poster_link, $poster_link)) { Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/#findComment-1199006 Share on other sites More sharing options...
vin_akleh Posted April 22, 2011 Author Share Posted April 22, 2011 should this work?? $title[1]='Faster'; $html_poster_link = file_get_contents('http://www.rottentomatoes.com/search/full_search.php?search=Faster'); if (preg_match('/<a href="\/m\/'.$title[1].'-2010\/.*?/i', $html_poster_link, $poster_link)) if i am looking for <a href="/m/faster-2010/" class="">Faster</a> if yes then why it is not working for me?? Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/#findComment-1204875 Share on other sites More sharing options...
vin_akleh Posted April 22, 2011 Author Share Posted April 22, 2011 ****************disregard the last post please*********************** should this work?? $title[1]='faster'; $html_poster_link = file_get_contents('http://www.rottentomatoes.com/search/full_search.php?search=Faster'); if (preg_match('/<a href="\/m\/'.$title[1].'-2\/.*?/i', $html_poster_link, $poster_link)) if i am looking for <a href="/m/faster-2010/" class="">Faster</a> if yes then why it is not working for me?? Link to comment https://forums.phpfreaks.com/topic/233126-preg_match-that-include-string-and-variable/#findComment-1204885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.