n00bert Posted December 15, 2008 Share Posted December 15, 2008 I have never had to use this function so it's all news to me..But could you tell me what I have wrong in this string of code? <?php str_replace("<a href=","<a href=http://".$server."/".$server."/", include("http://".$server."/".$server."/pbsvss.htm")); ?> Quote Link to comment https://forums.phpfreaks.com/topic/137042-str_replace-trouble/ Share on other sites More sharing options...
Adam Posted December 15, 2008 Share Posted December 15, 2008 I'm not sure whether or not include can be used within the function, but you have to assign the returned value to a variable: <?php $str = str_replace("<a href=","<a href=http://".$server."/".$server."/", include("http://".$server."/".$server."/pbsvss.htm")); ?> A Quote Link to comment https://forums.phpfreaks.com/topic/137042-str_replace-trouble/#findComment-715736 Share on other sites More sharing options...
JonnoTheDev Posted December 15, 2008 Share Posted December 15, 2008 str_replace takes strings as parameters, not functions! $string = "abc.php"; $string = str_replace("a","x", $string); // will include xbc.php include($string); Quote Link to comment https://forums.phpfreaks.com/topic/137042-str_replace-trouble/#findComment-715737 Share on other sites More sharing options...
Adam Posted December 15, 2008 Share Posted December 15, 2008 I don't think that's quite what he's trying to do. I think he's trying to append a full URL to all the links included from 'pbsvss.htm'.. A Quote Link to comment https://forums.phpfreaks.com/topic/137042-str_replace-trouble/#findComment-715741 Share on other sites More sharing options...
n00bert Posted December 15, 2008 Author Share Posted December 15, 2008 yeah, that's what i'm trying to do.. I just thought about it too and i'm gonna have to figure out how to open the file and read it first..Am I right? Quote Link to comment https://forums.phpfreaks.com/topic/137042-str_replace-trouble/#findComment-715747 Share on other sites More sharing options...
Adam Posted December 15, 2008 Share Posted December 15, 2008 I'd say so.. Very simple though: <?php $str = file_get_contents("http://".$server."/".$server."/pbsvss.htm"); $str = str_replace("<a href=","<a href=http://".$server."/".$server."/", include("http://".$server."/".$server."/pbsvss.htm")); ?> A Quote Link to comment https://forums.phpfreaks.com/topic/137042-str_replace-trouble/#findComment-715750 Share on other sites More sharing options...
n00bert Posted December 15, 2008 Author Share Posted December 15, 2008 yeah, I just figured it out but thanks guys.. here is what I used for those who are interested or have the same problem. <?php $pbsvss = fopen("http://".$server."/".$server."/pbsvss.htm", "r"); $contents = stream_get_contents($pbsvss); fclose($pbsvss); $string = str_replace("<a href=","<a href=http://".$server."/".$server."/", $contents); echo $string; ?> Quote Link to comment https://forums.phpfreaks.com/topic/137042-str_replace-trouble/#findComment-715754 Share on other sites More sharing options...
JonnoTheDev Posted December 15, 2008 Share Posted December 15, 2008 Better. This is incorrect Adam $str = file_get_contents("http://".$server."/".$server."/pbsvss.htm"); $str = str_replace("<a href=","<a href=http://".$server."/".$server."/", include("http://".$server."/".$server."/pbsvss.htm")); Include within function will not work Should be $str = file_get_contents("http://".$server."/".$server."/pbsvss.htm"); $str = str_replace("<a href=","<a href=http://".$server."/".$server."/", $str); Quote Link to comment https://forums.phpfreaks.com/topic/137042-str_replace-trouble/#findComment-715756 Share on other sites More sharing options...
Adam Posted December 15, 2008 Share Posted December 15, 2008 Ah yeah! My mistake! A Quote Link to comment https://forums.phpfreaks.com/topic/137042-str_replace-trouble/#findComment-715757 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.