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?? Quote 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. Quote 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"; } !!! Quote 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=) Quote 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/'); Quote 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? Quote 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 Quote 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)) { Quote 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?? Quote 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?? Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.