Jeed Jeed - 5 months ago 26
PHP Question

file get contents + preg match

i try to return a number on a div , i want to have the "01 55 33 44"

<div data-phone="01 55 33 44" class="agency_phone ">
Phone
</div>


I have try :

$url = "myurl";
$raw = file_get_contents($url);
preg_match('/<div data-phone="(.*)"class="agency_phone "/isU',$raw,$output);
echo $output[1];


I have no return,
somone have an idea ?

Thanks in advance.

Answer

index.php file have following content.

<?php
   $url = "test.php"; 
   echo $raw = file_get_contents($url); 
   preg_match('/data-phone="(.*)" class/', $raw, $output);
   echo $output[1];
?>

And other file source.php which have html tags.

<div data-phone="01 55 33 44" class="agency_phone ">
  Phone
</div>

It will return followig array

Array
(
  [0] => data-phone="01 55 33 44" class
  [1] => 01 55 33 44
)
Comments