Jump to content

Any Idea Why Str_Replace Isn't Working?


MySQL_Narb

Recommended Posts

Then...you're doing it wrong. You're really expecting an answer when you've given us a single line of code straight from the manual and you say it doesn't do what the manual says it will? Debug this. Are the arguments in the right order? Did you print a before and after? Is there other content on this page? Etc. So far your answer is "str_replace works, you're doing something wrong."

Link to comment
Share on other sites


<?php
//accounts
$file = 'proxy.txt';
$fh = fopen($file, 'r');
$data = fread($fh, filesize($file));
fclose($fh);

$ips = explode("\n", $data);

$ch = curl_init('HIDDEN');
curl_setopt($ch, CURLOPT_REFERER, 'HIDDEN');
curl_setopt($ch, CURLOPT_TIMEOUT, ;
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1');
curl_setopt($ch, CURLOPT_RETURNTRANSER, true);

//foreach($ips as $ip){
$returned = curl_exec($ch);
echo str_replace('MC, 'AC', $returned);
// curl_setopt($ch, CURLOPT_PROXY, $ip[0]);
// curl_setopt($ch, CURLOPT_PROXYPORT, $ip[1]);
// curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
//}
curl_close($ch);
?>

 

Yes. It successfully connects to the page. Something is returned. I've echoed it out with success, but the str_replace line doesn't replace anything like I should.

 

I've attempted to post a before and after, but it's the same exact thing. It just seems as if it's ignoring the replacing.

Edited by MySQL_Narb
Link to comment
Share on other sites

MC is missing a closing single quote.

 

Not the reason as the "actual code" has different values.

 

I honestly can't seem to figure out why the actual values are necessary, but here you go:

 


<?php
       //accounts
       $file = 'proxy.txt';
       $fh = fopen($file, 'r');
       $data = fread($fh, filesize($file));
       fclose($fh);

       $ips = explode("\n", $data);

$ch = curl_init('http://serverlist.us/index.php?in=17');
curl_setopt($ch, CURLOPT_REFERER, 'http://serverlist.us/index.php?server=17');
       curl_setopt($ch, CURLOPT_TIMEOUT, ;
       curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1');
curl_setopt($ch, CURLOPT_RETURNTRANSER, true);

//foreach($ips as $ip){
           $returned = curl_exec($ch);
           str_replace('securimage/securimage_show.php', 'http://www.serverlist.us/securimage/securimage_show.php', $returned);
//            curl_setopt($ch, CURLOPT_PROXY, $ip[0]);
//            curl_setopt($ch, CURLOPT_PROXYPORT, $ip[1]);
//            curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
//}
curl_close($ch);
?>

Link to comment
Share on other sites

The obvious answers are that the content doesn't contain the string you are trying to find/replace OR since this is a link and all you are replacing is the target url in the link, you won't see any thing different unless you look at the 'view source' of the page or hover your mouse over the link.

Link to comment
Share on other sites

The obvious answers are that the content doesn't contain the string you are trying to find/replace OR since this is a link and all you are replacing is the target url in the link, you won't see any thing different unless you look at the 'view source' of the page or hover your mouse over the link.

 

I do look in the view source, and it doesn't change.

 

Also, ignore the missing echo before str_replace - it's there, just not when I copied it over.

Link to comment
Share on other sites

I honestly can't seem to figure out why the actual values are necessary, but here you go:

Really? the function seems to work perfectly fine for everyone - and has for years. But, you are not getting the results you expect so youjump to the conclusion that the function is broken.

 

As Christian F. alluded to, in the code you finally provided you aren't doing anything with the returned value of str_replace()

str_replace('securimage/securimage_show.php', '[url="http://www.serverlist.us/securimage/securimage_show.php"]http://www.serverlis...rimage_show.php[/url]' $returned);

 

str_replace() does not modify the original value (if that is what you were thinking) - it only returns the modified string. You need to do something with that returned value (otherwise why run it in the first place).

Link to comment
Share on other sites

And now you see why posting your ACTUAL code is important.

 

Copy and paste doesn't remove random vital parts of your code. So either you're STILL not showing the actual code, or you lied about loosing it in pasting it.

Link to comment
Share on other sites

Let me make my previous statement come to your attention:

 

Also, ignore the missing echo before str_replace - it's there, just not when I copied it over.

 

It's not being used to modify the original variable/value. I'm echoing the results of the str_replace function.

Link to comment
Share on other sites

Let me make my previous statement come to your attention:

 

Also, ignore the missing echo before str_replace - it's there, just not when I copied it over.

 

It's not being used to modify the original variable/value. I'm echoing the results of the str_replace function.

 

You are the one asking for help. It is your responsibility to provide the information we need to provide that help. If you can't even be bothered to post accurate code then why ask for help?

 

Look at it this way. You ask for help providing nothing for us to provide that help. Then when you finally decide to post some code and we point out problems in that code you come back and state that we should just ignore that error. Why are you wasting our time when we are only trying to help?

 

Let's go back to your original post

 


$returned = curl_exec($ch);
echo str_replace('mc', 'ac', $returned);

 

It doesn't actually replace it when it is outputted/echo. Any ideas?

 

Provide the content of $returned that you say is not working with that str_replace(). As shown in the example Barand provided with some mock content of $returned it worked perfectly fine.

Edited by Psycho
Link to comment
Share on other sites

Not the reason as the "actual code" has different values.
Well maybe you can help me with my dog. She's really sick, here's a photo:

 

     ,   /-.
    ((___/ __>
    /    }
    \ .--.(    
     \\   \\

It's not actually her, but that shouldn't be a problem right? We absolutely positively cannot help you fix your code by looking at someone else's. Show a before and after proof that a built-in language function that works for tens of millions of people every day is not working for you.

Edited by ManiacDan
Link to comment
Share on other sites

After removing all the errors from the code posted:

 

- CURLOPT_RETURNTRANSFER -- Missing the "F" in transfer

- Added a check to see if the file exists (not 100% need, but added)

- Added a comma to the str-replace function

 

I came up with this:

<?php
//accounts
$file = 'proxy.txt';
$data = "";
if(is_file($file)){
$data = file_get_contents($file);
}
$ips = explode("\n", $data);
$ch = curl_init('http://serverlist.us/index.php?in=17');
curl_setopt($ch, CURLOPT_REFERER, 'http://serverlist.us...x.php?server=17');
curl_setopt($ch, CURLOPT_TIMEOUT, ;
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$returned = curl_exec($ch);
$opt = str_replace('securimage/securimage_show.php', 'http://www.serverlis...rimage_show.php', $returned);
curl_close($ch);
echo $opt;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.