For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2005 > read in webpage and modify..









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author read in webpage and modify..
grinder

2005-02-15, 8:56 pm

Hey guys....
I tried to make one of those silly webpage translators... it reads in the
page, and applys a modification to all text not in HTML tags.
What I wanted to go was add "ong" after every consonant (don't ask why! lol)

What I found was that when I added "ong", the same rule was applied to the
"ong" I just added, giving "onongononongong" for example......

What I need, is something which will do this, for example:

Turn "hello" into "hongelonglongo"

Any ideas?
-Grinder


Andy Hassall

2005-02-15, 8:56 pm

On Tue, 15 Feb 2005 23:21:53 GMT, "grinder" <gor@sbcglobal.net> wrote:

>I tried to make one of those silly webpage translators... it reads in the
>page, and applys a modification to all text not in HTML tags.
>What I wanted to go was add "ong" after every consonant (don't ask why! lol)
>
>What I found was that when I added "ong", the same rule was applied to the
>"ong" I just added, giving "onongononongong" for example......
>
>What I need, is something which will do this, for example:
>
>Turn "hello" into "hongelonglongo"


Yongou congoulongdong usonge pongrongegong_rongeponglongaconge,
songomongetonghonginonggong longikonge tonghonge fongolonglongowonginonggong:

<?php
$str = "You could use preg_replace, something like the following:";
print preg_replace('/([bcdfghjklmnpqrstvwxyz])/i', '$1ong', $str);
?>

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Geoff Berrow

2005-02-15, 8:56 pm

I noticed that Message-ID:
<luvQd.10383$D34.9373@newssvr12.news.prodigy.com> from grinder contained
the following:

>What I need, is something which will do this, for example:
>
>Turn "hello" into "hongelonglongo"

<?php
$string="hello world";
$output="";

for($i=0;$i<strlen($string);$i++){
switch ($string{$i}) {
//add all consonants here...I've just done a few
case "d":
$output.="dong";
break;
case "h":
$output.="hong";
break;
case "l":
$output.="long";
break;
case "w":
$output.="wong";
break;
case "r":
$output.="rong";
break;
default:
$output.=$string{$i};
break;
}

}
print $output;
?>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Geoff Berrow

2005-02-16, 3:57 am

I noticed that Message-ID: <tr25119k8jdnq9c4bb1tpba4do0p3hd3le@4ax.com>
from Andy Hassall contained the following:

><?php
>$str = "You could use preg_replace, something like the following:";
>print preg_replace('/([bcdfghjklmnpqrstvwxyz])/i', '$1ong', $str);
>?>


Memo to self: Make solid effort to learn regex.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
grinder

2005-02-16, 3:57 am

That's awesome thanks!
I'd started using strtr with an array of consonants.... it works, but I'll
try the regex, doing it in one line appeals!!!
NOW........
I'm trying to read a webpage into a variable using fsockopen, ignore the
tags and process using the above!
Any ideas on that?

You guys rock!

"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:tr25119k8jdnq9c4bb1tpba4do0p3hd3le@
4ax.com...
> On Tue, 15 Feb 2005 23:21:53 GMT, "grinder" <gor@sbcglobal.net> wrote:
>
>
> Yongou congoulongdong usonge pongrongegong_rongeponglongaconge,
> songomongetonghonginonggong longikonge tonghonge
> fongolonglongowonginonggong:
>
> <?php
> $str = "You could use preg_replace, something like the following:";
> print preg_replace('/([bcdfghjklmnpqrstvwxyz])/i', '$1ong', $str);
> ?>
>
> --
> Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool



grinder

2005-02-16, 3:57 am

OK I have that part going.
I have it reading in a web page and translating it... I have a really crap
way of detecting HTML tags and ignoring them....
The problem now, is if the page uses relative paths for their images, my
script thinks it should pull the images from my server, and not theirs... so
what I need to do , is change :
img src="/images/whatever.gif" into..
img src=http://whatever.com/images/whatever.gif

see what I mean?
Here's the script:

<?php
$loc = "http://www.google.com";
$handle = fopen($loc, "rb");
$content = '';
$contents = '';
while (!feof($handle)) {
$content .= fread($handle, 4096);
}
fclose($handle);
for ($i = 0, $j = strlen($content); $i < $j; $i++) {

if (strstr('<',$content[$i])) {
$tagstart = 1;
}

if (strstr('>',$content[$i])) {
$tagstart = 0;
}

if (strstr(' ',$content[$i])) {
$tagstart = 1;
}

if ($tagstart == 1) {
echo $content[$i];
}

if ($tagstart == 0) {
echo preg_replace('/([bcdfghjklmnpqrstvwxyz])/i', '$1ong',
$content[$i]);
$tagstart = 0;
}

}
?>


"grinder" <gor@sbcglobal.net> wrote in message
news:k5xQd.10404$D34.2632@newssvr12.news.prodigy.com...
> That's awesome thanks!
> I'd started using strtr with an array of consonants.... it works, but I'll
> try the regex, doing it in one line appeals!!!
> NOW........
> I'm trying to read a webpage into a variable using fsockopen, ignore the
> tags and process using the above!
> Any ideas on that?
>
> You guys rock!
>
> "Andy Hassall" <andy@andyh.co.uk> wrote in message
> news:tr25119k8jdnq9c4bb1tpba4do0p3hd3le@
4ax.com...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com