Jump to content

how to replace these strings...


becu

Recommended Posts

Hi here's my problem:

<div align="center"><a href="link1">Text1</div>
Some text I want to keep.
<div align="center"><a href="link2">Text2</div>
Some other text I want to keep.
<div align="center"><a href="link3">Text3</div>
Some other text I want to keep.
<div align="center"><a href="link4">Text4</div>
Some other text I want to keep.

This is what I want, Output:
Some text I want to keep.
Some other text I want to keep.
Some other text I want to keep.
Some other text I want to keep.


I tried to use ereg_replace but it stripped out everything from the first <div align="center"> to the last </div><br/>.
Thank you so much for your help.
Link to comment
https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/
Share on other sites

[quote author=Jocka link=topic=103999.msg414602#msg414602 date=1155401149]
I'm not 100% sure what you mean.. you just want it to output the text.. no links or anything?
[/quote]
yes, just those text in between. Or in other words, I want to get rid off all the div, a tags, and text1 -> text4
You'd need to set those as variables then use the 'echo' command. Like this:

$Text1 = "blah";
$Text2 = "blah blah";
$Text3 = "blah blah blah";
$Text4 = "blah blah blah blah";


echo $Text1<br \>;
echo $Text2<br \>;
echo $Text3<br \>;
echo $Text4<br \>;

Now, the question is... how is that text getting placed into your HTML? Via a form input? In order for it to be extracted it needs to know how it got there. If it's posted via a form then the variables are set by the form field names using the $_POST command and your 'action' script parses the form input and displays the HTML and results of the form. Need a bit more detail on how this is created :)
No, I don't want those text1, text2, text3, text4.. .
I only want
"Some text I want to keep.
Some other text I want to keep.
Some other text I want to keep.
Some other text I want to keep."

A simple case of this which is:
$str = '<div align="center"><a href="link1">Text1</div>
Some text I want to keep.';
ereg_replace('<div align="center">(.*)</div>', '', $str);

output: Some text I want to keep.

but in this case I have more than one occurance of <div>, <a> tag, if I tried ereg_replace, it will take from the first <div align="center"> to the last </div> which will strip out all the text I want.
yes, i try to read from a file.
This is an error i get from orio code:
Fatal error: Maximum execution time of 30 seconds exceeded in...

in my first post, if I use
ereg_replace('<div align="center">(.*)</div>', '', $str);

output would be: "Some other text I want to keep" (the last text). all the other text (that I also want) in between will be stripped out.

Any idea?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.