Page 1 of 1

Replace between 2 objects?

Posted: Fri May 30, 2003 6:19 pm
by Mr. Tech
Hi!

Is there a way to replace text between 2 objects? E.G:

Code: Select all

<!-- START Replace -->
This is what you replace!
<!-- END Replace -->
So what I want to do is to be able to replace what's between START and END Replace. What code would I need to do that?

Do you understand?

Thanks

Posted: Tue Jun 03, 2003 11:52 pm
by Mr. Tech
Anyone?

Posted: Wed Jun 04, 2003 1:31 am
by detrox
Maybe you can use fopen() and fwrite() to access this file. To find the begin tag and end tag then get the inner text.

Is this what you want?

Posted: Wed Jun 04, 2003 2:06 am
by []InTeR[]
If the 'tags' are the onlything on 1 line, use file.

If it's not, i let somebody els do the f* job :)

PS: I hate working with file's. I let yapter do all the html stuff.

Posted: Wed Jun 04, 2003 9:06 am
by McGruff
Sounds like a job for preg_replace.

Posted: Wed Jun 04, 2003 9:41 am
by bradvan
When you say that you want to replace the text, do you mean you want it to be dynamic as in a variable or do you just want to straight search a file and replace the text with different static text?

If you want the text to be dynamic (that is change depending on user requests) then you could replace the text with a php variable e.g $text, and define $text depending on some condition.

e.g:

<?php

if ($_GET["request"] == "this")
{
$text = "add this text";
}

else $text = "add this text instead";
?>

<!-- start replace -->
<? print "$text"; ?>
<!-- end replace -->


Is this the sort of thing you are talking about?