Home     Articles & Projects     Products & Web Services     Forum

Rip a part of html

Hi I need away to get the last part of this URL

{link saved}

The data after the 6th ,

I thought you I would post a

I thought you I would post a sample but I still don't know how to get the data I want

542,1,800,800,535,128,We aRe oNe

What I am wanting to get is the very end ,(what text here) in this example we want to get ,We aRe oNe

If you can help that would be so nice. also to know how to get the first one 542, that would be nice thanks.

Hi Russell, explode() is the

Hi Russell,

explode() is the function to use when wanting to extract values from a comma separated string. So to extract the text on the end - assuming that it is always the same number of fields:

<?php
  $text
= "542,1,800,800,535,128,We aRe oNe";
 
$parts = explode(",",$text);
 
$words = $parts[6];
  print
$words;
?>

This will print "We aRe oNe".

If the number of fields is not always known, but you always want the last field; use count() which tells you how many entries are the $parts array; for example:

<?php
  $text
= "542,1,800,800,535,128,We aRe oNe";
 
$parts = explode(",",$text);
 
$words = $parts[count($parts)-1];
  print
$words;
?>

Hope this helps!
Cheers,
David.

Thanks David, That helps

Thanks David,
That helps alot. I am only now having issue with accessing the page it is on.

{link saved}

The header of that file has a no-cache thing I was wondering anyway to get around that?
Thanks

Hi Russell, The headers

Hi Russell,

The headers shouldn't affect accessing the file. The easiest method, assuming that your web server is able to fopen() remote documents via URL would be:

$text = file_get_contents("http://www.example.com/7.html");

Alternatively, if that doesn't work CURL may be installed, the equivalent code the above being:

$ch = curl_init("http://www.example.com/7.html");
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$text = curl_exec ($ch); 

Hope this helps!
Cheers,
David.

Hi David, That sadly did not

Hi David,
That sadly did not work I even tried

<?php
$ch
= curl_init("{link saved}");
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_USERAGENT,"Interweb Explorer");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
$text = curl_exec ($ch); 
print
$text;
?>

I get a blank white page, however that script works when accessing Google.com or sites like Yahoo or alexa etc...

When I run this

When I run this script

<?php
$ch
= curl_init("http://64.15.67.4/7.html");
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$text = curl_exec ($ch); 
print
$text;
?>

I get this
ICY 404 Resource Not Found icy-notice1:
SHOUTcast Distributed Network Audio Server/Linux v1.9.8
icy-notice2:The resource requested was not found

Ok was able to get it to

Ok was able to get it to work, but only for shoutcast stations broadcasting on port 80.

There seems to be an issue using the following code, if the station has another port other then 80. Any ideas google searches did not help.

<?php
$ch
= curl_init("http://radio.bigbeats.ru:9054/7.html");
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$text = curl_exec ($ch); 
print
$text;
?>

The URL is radio. bigbeats . ru

Hi Russell, Have you tried

Hi Russell,

Have you tried setting the port as a CURL option? For example:

<?php
$ch
= curl_init("http://radio.bigbeats.ru/7.html");
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_PORT,9054);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$text = curl_exec ($ch);
print
$text;
?>

Cheers,
David.

Yes I tried that with a

Yes I tried that with a number of stations with port numbers but did not work, I will try the script on my local computer and not the webserver that I host my sites with, I will let you know if that makes a difference.

It is the web host provider.

It is the web host provider. I don't know what to do.
It worked on my home PC mind you I am using xampp

maybe its a setting.