Find and remove words?

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
abyssisthebest
-


Joined: 30 Jun 2005
Posts: 319
Location: Boston, UK

PostPosted: Tue Nov 29, 2005 7:01 pm    Post subject: Find and remove words? Reply with quote

How can i search a page and remove certain words from it?

for example if a website contains control panel its replaced with *ontrol *anel

I tried this, but it dosn't work:
Code:
<?php
// The text string
$url = readfile ("http://www.abysspanel.co.uk/");

// The word we want to replace
$oldWord = "control panel";

// The new word we want in place of the old one
$newWord = "*ontrol *panel";

// Run through the text and replaces all occurrences of $oldText
$url = str_replace($oldWord , $newWord , $url);

// Display the new text
echo $url

?>

_________________
My online Portfolio
Back to top View user's profile Send private message Send e-mail MSN Messenger
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Tue Nov 29, 2005 7:25 pm    Post subject: Re: Find and remove words? Reply with quote

abyssisthebest wrote:
How can i search a page and remove certain words from it?

for example if a website contains control panel its replaced with *ontrol *anel

I tried this, but it dosn't work:
Code:
<?php
// The text string
$url = readfile ("http://www.abysspanel.co.uk/");

// The word we want to replace
$oldWord = "control panel";

// The new word we want in place of the old one
$newWord = "*ontrol *panel";

// Run through the text and replaces all occurrences of $oldText
$url = str_replace($oldWord , $newWord , $url);

// Display the new text
echo $url

?>


Try not using readfile, because readfile also prints the output too I believe.
Code:
$url = file("http://www.abysspanel.co.uk/");

_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
SQL Maestro
-


Joined: 15 Dec 2005
Posts: 1

PostPosted: Thu Dec 15, 2005 1:46 pm    Post subject: Reply with quote

some better code...
Code:

<?php
// The word we want to replace
$oldWord = 'control panel';

// The new word we want in place of the old one
$newWord = '*ontrol *panel';

// The text string
$oldWord=preg_replace('/ +/','\s',&$oldWord);
foreach(file('http://www.abysspanel.co.uk/') as $url)
   echo preg_replace('/'.$oldWord.'/i',$newWord,&$url);

?>

_________________
Regards,

Use the power of new MySQL 5 features with MySQL Maestro
Back to top View user's profile Send private message Visit poster's website
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Thu Dec 15, 2005 2:08 pm    Post subject: Reply with quote

Readfile only returns true or false depending on if the file was read or not. Try using fopen instead. Not sure if it will work though...
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group