MySQL_Narb Posted September 30, 2012 Share Posted September 30, 2012 $returned = curl_exec($ch); echo str_replace('mc', 'ac', $returned); It doesn't actually replace it when it is outputted/echo. Any ideas? Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted September 30, 2012 Share Posted September 30, 2012 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." Quote Link to comment Share on other sites More sharing options...
MySQL_Narb Posted September 30, 2012 Author Share Posted September 30, 2012 (edited) <?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 September 30, 2012 by MySQL_Narb Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 30, 2012 Share Posted September 30, 2012 Post your actual code, you've clearly edited that one. Also you only have one echo, so there's no evidence you're comparing the two strings. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 30, 2012 Share Posted September 30, 2012 works for me <?php $returned = 'MCabcdeMCfghjk'; echo str_replace('MC', 'AC', $returned); // --> ACabcdeACfghjk ?> Quote Link to comment Share on other sites More sharing options...
xyph Posted September 30, 2012 Share Posted September 30, 2012 MC is missing a closing single quote. Quote Link to comment Share on other sites More sharing options...
MySQL_Narb Posted September 30, 2012 Author Share Posted September 30, 2012 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); ?> Quote Link to comment Share on other sites More sharing options...
Christian F. Posted September 30, 2012 Share Posted September 30, 2012 No wonder it doesn't do anything, really, as you're not saving the results. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 1, 2012 Share Posted October 1, 2012 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. Quote Link to comment Share on other sites More sharing options...
MySQL_Narb Posted October 1, 2012 Author Share Posted October 1, 2012 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 1, 2012 Share Posted October 1, 2012 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). Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 1, 2012 Share Posted October 1, 2012 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. Quote Link to comment Share on other sites More sharing options...
MySQL_Narb Posted October 1, 2012 Author Share Posted October 1, 2012 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 1, 2012 Share Posted October 1, 2012 And now you see why posting your ACTUAL code is important. Copy and paste doesn't remove random vital parts of your code. So you're STILL not showing the actual code Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 1, 2012 Share Posted October 1, 2012 (edited) 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 October 1, 2012 by Psycho Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 1, 2012 Share Posted October 1, 2012 (edited) 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 October 1, 2012 by ManiacDan Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 1, 2012 Share Posted October 1, 2012 I'm going to venture a guess, that since you have marked the thread as solved, that once you actually looked at the value in the data, you noticed that it wasn't exactly what you were trying to match in the str_replace statement. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 1, 2012 Share Posted October 1, 2012 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; ?> Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 1, 2012 Share Posted October 1, 2012 The "real" code had multiple syntax errors in it (which won't run at all) and wasn't using str_replace properly. I think we can safely assume those were his problems. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.