Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Find String, Replace It, Save It...


[SOLVED] Find String, Replace It, Save It...

Reply
  #1 (permalink)  
Old 12-26-08, 10:46 AM
!Unreal's Avatar
!Unreal !Unreal is offline
Wannabe Coder
 
Join Date: Aug 2008
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Find String, Replace It, Save It...

Ive got this...What it does is finds an ad on a page then replaces it with another one.

Its not working and I cant see where Im going wrong.

PHP Code:

<?php

function get_inner_string($a,$b,$c)
{
  
$y explode($b,$a);
  
$x explode($c,$y[1]);
  return 
$x[0];
}

$file 'cache/94ddd435242c289003eca450b102df52.html';

$open_file file_get_contents($file);

$find_ad get_inner_string($open_file'<!-- Begin: AdBrite, Generated: 2008-12-18 16:23:11  -->''<!-- End: AdBrite -->');

$new_ad 'NEW AD';

$new_result str_replace($new_ad$find_ad$open_file);

echo 
$new_result;

file_put_contents($open_file$new_result);
?>
Thanks
__________________
Free Online Movies
Reply With Quote
  #2 (permalink)  
Old 12-26-08, 11:07 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by !Unreal View Post
Ive got this...What it does is finds an ad on a page then replaces it with another one.

Its not working and I cant see where Im going wrong.
What part isn't working? Is it not finding the ad, not replacing the ad, is it crashing?
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #3 (permalink)  
Old 12-26-08, 11:08 AM
!Unreal's Avatar
!Unreal !Unreal is offline
Wannabe Coder
 
Join Date: Aug 2008
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry, its kind of vital that bit Its not replacing or saving.
__________________
Free Online Movies
Reply With Quote
  #4 (permalink)  
Old 12-26-08, 11:42 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
It's not working because the parameters need to be entered in a different order in the str_replace function, like this:
PHP Code:

str_replace ($find_ad$new_ad$open_file); 

have you tried replacing it using regular expressions? it's ways easier
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 12-26-08, 11:52 AM
!Unreal's Avatar
!Unreal !Unreal is offline
Wannabe Coder
 
Join Date: Aug 2008
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Ah...Its all fixed now. Thank you UnrealEd. I make alot of these small mistakes which end up making big differences lol.
__________________
Free Online Movies
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OOP C-Sharp DB Access Wrapper Question digioz ASP.NET 1 09-08-08 09:54 AM
search function using dot net nishudude_13 Windows .NET Programming 1 08-28-08 11:28 AM
replace pattern-problm with pointers Erev0s C/C++ 0 05-25-04 02:30 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 08:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.