Forum Moderators: coopster

Message Too Old, No Replies

str_replace?

         

TGecho

2:14 pm on May 31, 2003 (gmt 0)

10+ Year Member



First of all I'm a total newbie when it comes to php, so you'll have to be very clear (and patient ;).

Okay, say I've got a page that goes something like this

...<body>
<!-- header -->

<p>Body text</p>

<!-- footer -->
</body>...

I want to use php to replace the comments with code I've read from external files and stored in variables. I've found stuff about using str_replace, but I can't figure out how it works.

Thanks,
Erik

jatar_k

5:11 pm on May 31, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



str_replace seems a little heavy for what you want to do. Is this some kind of template?

What about using include [ca3.php.net]? You could then include a file which reds the value you need and then echo's it.

A little more explanation of what you want to do, as opposed to how, might help give you a little better insight.

hcs420

7:20 pm on May 31, 2003 (gmt 0)

10+ Year Member



Hi,
You can use str_replace.
If you want to remove comments from some html page i.e. from other url etc., then you have to open a file using fopen and get the data in string.

If you are using plain text then it can be done in this way :
$mytext=".... your text"
$uncommentedtext = str_replace("<!--","",$mytext);

TGecho

9:37 pm on May 31, 2003 (gmt 0)

10+ Year Member



Basically I want to be able to add various bits of code throughout the page when it is requested from the server (by replacing those special comments). Part of that would be for the template (header, footer), but there would be a bunch of other things I would use it for.

I guess my goal is to not hardcode the same structural code for certain page elements.

If there's a better way to do this, I'm open to suggestions.

jatar_k

9:50 pm on May 31, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe something in this thread might help

A dynamic site in 2 minutes [webmasterworld.com]