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
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
Link to comment
Share on other sites

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 :)
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.