Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include with str_replace?

Status
Not open for further replies.

BitFuzzy

Technical User
Jun 8, 2001
343
US
Here's what I'm trying to do.

Site abc.com has a link file links.php, which I'm including into a page using <? include (&quot;abc.com/links.php&quot;); ?>

Is it posible to use str_replace on the content of the included file?

I've tried

<?
$xlink = include(&quot;echo str_replace(&quot;index.html&quot;, &quot;nothing.html&quot;, $xlink);
?>

** example replaces index.html with nothing.html**

but needless to say I got nowhere

anyone have any suggestions?
 
When you use include() ins the form:
Code:
$xlink = include(&quot;somefile.php&quot;);

you must tell php what to return in the include file.
Here is the exmaple from the php documentation:
Code:
return.php
<?php

$var = 'PHP';

return $var;

?>

noreturn.php
<?php

$var = 'PHP';

?>

testreturns.php
<?php

$foo = include 'return.php';

echo $foo; // prints 'PHP'

$bar = include 'noreturn.php';

echo $bar; // prints 1

?>
 
BitFuzzy:
No, you can't modify the contents of the file as you use it with include().

However, if this page is a list of links and not PHP program code, you should be able to read the contents of the file using fopen() and fgets() or file(), then modify the links in memory before printing them using print().

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top