arif_shariati Posted December 16, 2010 Share Posted December 16, 2010 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 More sharing options...
solon Posted December 16, 2010 Share Posted December 16, 2010 you can use the explode() function check this out: http://php.net/manual/en/function.explode.php Link to comment https://forums.phpfreaks.com/topic/221862-parse-data/#findComment-1148086 Share on other sites More sharing options...
johnny86 Posted December 16, 2010 Share Posted December 16, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.