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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.