Thomisback Posted July 19, 2008 Share Posted July 19, 2008 Hi, I have been trying to extract substrings from a web page but it does not return ANYTHING. I'm trying to extract the code after "sku" For Example: <a href='/details.dx/sku.3903' style="text-decoration: none; font-size: 8pt; font-family: Arial;"> I want to extract "3903" This is the script I made: <?php set_time_limit(0); function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } $ch = curl_init("http://www.thelink.com"); curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); $data = curl_exec($ch); if (curl_errno($ch)){ echo curl_error($ch); }else{ curl_close($ch); } $start = "<a href='/details.dx/sku."; $end = "' style=\"text-decoration: none;\">"; $fullstring = $data; $parsed = get_string_between($fullstring, $start, $end); $user = $parsed; ?> But it does not return any results! Does anyone see a mistake I made? Kind regards Quote Link to comment https://forums.phpfreaks.com/topic/115576-solved-extracting-substrings/ Share on other sites More sharing options...
Thomisback Posted July 19, 2008 Author Share Posted July 19, 2008 Solved, I didn't echo it Quote Link to comment https://forums.phpfreaks.com/topic/115576-solved-extracting-substrings/#findComment-594170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.