The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hi, I'm on the PHP learning trail and trying to modify a basic script to perform a few more functions (Thanks for your help on resources - up v.late last night!).

Can anyone give me some help with the following (sorry its long - just hoped to explain it clearly):

I'm trying to modify a remote grabber script to fetch some headlines link.

- This is an example source of what I want to fetch:

<!--This is where I want the grab to start -->
<p><a href="/article1.html"><font size="2">This is the link to article 1</font></a><br>
<font color="#FFCC66">This is the intro text to article 1</font></p>
<p><a href="/article2.html"><font size="2">This is the link to article 2</font></a><br>
<font color="#FFCC66">This is the intro text to article 2</font></p>
<p><a href="/article3.html"><font size="2">This is the link to article 3</font></a><br>
<font color="#FFCC66">This is the intro text to article 3</font></p>
<p><a href="/article4.html"><font size="2">This is the link to article 4</font></a><br>
<font color="#FFCC66">This is the intro text to article 4</font></p>
<!--This could be used as grab end -->

- OK: now if I use the following script I can get this basic information to start playing with:

$GrabURL = "http://www.SomeSite.Com/index.html"; //- Complete URL of the page your grabbing from!
$GrabStart = "<!--This is where I want the grab to start -->";
$GrabEnd = "<!--This could be used as grab end -->";

<p><a href="/article1.html">This is the link to article 1</a><br>
<a href="/article2.html">This is the link to article 2</a><br>
<a href="/article3.html">This is the link to article 3</a></p>

Note: the above output does not contain the article 4 link, or any of the intro text of any article.

So replacing the font tags (with nothing) can be easily done by str_replace.

Qu1: However - how can I automatically remove the 'intro text to articles' given that the text is likely to be constantly changing?

Could you use the same 'everything between' (.*) function and the replace this with nothing? Here it would be 'replace everything between <font color="#FFCC66"> and </font> with nothing?

Qu2: As I dont want ANY font tags in my final output (I'll use CSS on the output) is there any way of removing All font tags in one operation rather than str_replace each one individually. I understand that if I'm along the right lines with Qu1, the answer to Qu2 would have to come as a subsequent str_replace function for the Qu1 replace to work!

Qu3: How can I limit the output of the number of links I want to any given number? The simple answer of course would be to have the end grab between just after the number of links I want (in the example between links 3 and 4). However there is no unique code (for grab end) between these two links (as the links will keep changing), so it can't be done like this. Also I couldn't use the replace function as all the links subsequent to link 3, could again be constantly changing.

I see the only possible solution as something to do with the print function - in that you could possibly set it to print only the first 3 links. However, as a complete (although willing)beginner I can't really get my head round on how to do this.

I'd be really grateful if anyone could show me an example of how best I could overcome these problems. As a beginner and still at 'learning by example stage' I would really appreciate it if someone could show me via a working example.

I know I'm asking a lot, but help with this would be really appreciated.