View previous topic :: View next topic |
Author |
Message |
abyssisthebest -
Joined: 30 Jun 2005 Posts: 319 Location: Boston, UK
|
Posted: Tue Nov 29, 2005 7:01 pm Post subject: Find and remove words? |
|
|
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 |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Tue Nov 29, 2005 7:25 pm Post subject: Re: Find and remove words? |
|
|
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 |
 |
 |
SQL Maestro -
Joined: 15 Dec 2005 Posts: 1
|
Posted: Thu Dec 15, 2005 1:46 pm Post subject: |
|
|
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 |
|
 |
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Thu Dec 15, 2005 2:08 pm Post subject: |
|
|
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 |
|
 |
|