Jump to content

Parse data


arif_shariati

Recommended Posts

Hey guys i am trying to parse selected data from a website. here is the sample code i have done

 

$url="some website":

$string=file_get_contents($url);

$mystring="john":// this is the string i want to find from that website

 

how to get this word "john" form that string.

 

second thing, suppose this is the word on the website [John  23  40]. i want to get all three values {John,23,40} to separate table columns. how to do that?

Link to comment
https://forums.phpfreaks.com/topic/221862-parse-data/
Share on other sites

You should take a look into regular expressions:

http://fi.php.net/manual/en/book.pcre.php

And especially this function: http://fi.php.net/manual/en/function.preg-match-all.php

 

but to find something like "john [number] [number]" you could use something like

<?php 
preg_match_all("/john \d+ \d+/i", "this is some string that contains john 45 23 right?", $matches);
print_r($matches);

// Result:
//Array
//(
//    [0] => Array
//        (
//            [0] => john 45 23
//        )
//
//)

?>

Link to comment
https://forums.phpfreaks.com/topic/221862-parse-data/#findComment-1148096
Share on other sites

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.