Jump to content

[SOLVED] Extracting substrings


Thomisback

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/115576-solved-extracting-substrings/
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.