Jump to content

[SOLVED] Quick preg_match_all Question


JSHINER

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/75532-solved-quick-preg_match_all-question/
Share on other sites

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";
     }
     
}

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.