JSHINER Posted October 31, 2007 Share Posted October 31, 2007 javascript:let("101 460 179 142 142 188 51 51 597 380 355 635 44 188 274",649,387) The above is what I am working with (many of these among text on a page) Using this: <?php $seed = 'http://www.site.com/page.html'; $data = file_get_contents($seed); if (preg_match_all("/let[a-zA-Z0-9.-]+/", $data, $links)) { @header("Content-type: text/plain"); for ($i=0;$i<count($links[0]);$i++) { echo $links[0][$i]. "\n"; } } ?> I would like to display: let("101 460 179 142 142 188 51 51 597 380 355 635 44 188 274",649,387) What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/ Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 here you go if (preg_match_all("/let[^\)]+\)/", $data, $links)) Quote Link to comment https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/#findComment-382122 Share on other sites More sharing options...
JSHINER Posted October 31, 2007 Author Share Posted October 31, 2007 Now let's say I wanted to replace "380" with "k" and "355" with "w" how could I make it so before they displayed the sets of numbers were replaced with corresponding letters? Quote Link to comment https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/#findComment-382134 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 here you go but one constraint you have to have all your numbers defined in $arrNumbers array $data = 'javascript:let("101 460 179 142 142 188 51 51 597 380 355 635 44 188 274",649,387)'; $arrNumbers = array(380 => "k", 355 => "w"); if (preg_match_all("/let[^\)]+\)/", $data, $links)) { @header("Content-type: text/plain"); for ($i=0;$i<count($links[0]);$i++) { print @preg_replace("/\b(\d+)\b/e","\$arrNumbers[\\1]",$links[0][$i]). "\n"; } } Quote Link to comment https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/#findComment-382142 Share on other sites More sharing options...
JSHINER Posted October 31, 2007 Author Share Posted October 31, 2007 How can I get this to replace a space " " with no space? Quote Link to comment https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/#findComment-382150 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 use string replace print str_replace(" ","",@preg_replace("/\b(\d+)\b/e","\$arrNumbers[\\1]",$links[0][$i])). "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/#findComment-382153 Share on other sites More sharing options...
JSHINER Posted October 31, 2007 Author Share Posted October 31, 2007 And lastly (I hope ) How can I get this in there? substr($links[0][$i], 5, -4) - so it gets rid of the first 5 and last 4 ( the let(" and the ",,) ) Quote Link to comment https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/#findComment-382160 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 for making it simple I broke it up $strString = str_replace(" ","",@preg_replace("/\b(\d+)\b/e","\$arrNumbers[\\1]",$links[0][$i])); $strString = substr(substr($strString, 5, strlen($strString)-5),0, -4); print $strString; hope it helps Quote Link to comment https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/#findComment-382179 Share on other sites More sharing options...
JSHINER Posted October 31, 2007 Author Share Posted October 31, 2007 Perfect thanks! Quote Link to comment https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/#findComment-382196 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.