September 8, 2013

extract info from another web page

Catalin Preda’s Question:

I have this test.php where i have this info :

callername1 : 'Fernando Verdasco1'
callername2 : 'Fernando Verdasco2'
callername3 : 'Fernando Verdasco3'
callername4 : 'Fernando Verdasco4'
callername5 : 'Fernando Verdasco5'

this page automatically changes that name every 10 min

In this another page test1.php

I need a php code that takes only the name of the callername3 and echo’it

Fernando Verdasco3

I’ve tried this like so test1.php?id=callername3

<?php 
  $Text=file_get_contents("test.php");
  if(isset($_GET["id"])){
     $id = $_GET["id"];
     parse_str($Text,$data);
     echo $data[$id];
  } else {
     echo "";
  }

?>

but no result.

Is there any other option?

If i have “=” instade of “:”

callername1 = 'Fernando Verdasco1'
callername2 = 'Fernando Verdasco2'
callername3 = 'Fernando Verdasco3'
callername4 = 'Fernando Verdasco4'
callername5 = 'Fernando Verdasco5'

And i use This php Code it works

<?php 
    $Text=file_get_contents("test.php")
    ;preg_match_all('/callername3='([^']+)'/',$Text,$Match); 
    $fid=$Match[1][0]; 
    echo $fid; 

?>

i need this to work with “:”

Help?

There is a rather simple approach to tihs:

$fData = file_get_contents("test.php");
$lines = explode("n", $fData);
foreach($lines as $line) {
    $t = explode(":", $line);

    echo trim($t[1]); // This will give you the name
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!