becu Posted August 12, 2006 Share Posted August 12, 2006 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 More sharing options...
Jocka Posted August 12, 2006 Share Posted August 12, 2006 I'm not 100% sure what you mean.. you just want it to output the text.. no links or anything? Link to comment https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/#findComment-73736 Share on other sites More sharing options...
becu Posted August 12, 2006 Author Share Posted August 12, 2006 [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 https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/#findComment-73737 Share on other sites More sharing options...
simcoweb Posted August 12, 2006 Share Posted August 12, 2006 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 https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/#findComment-73742 Share on other sites More sharing options...
becu Posted August 12, 2006 Author Share Posted August 12, 2006 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 https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/#findComment-73743 Share on other sites More sharing options...
Orio Posted August 12, 2006 Share Posted August 12, 2006 What's wrong with what you said?ereg_replace('<div align="center">(.*)</div>', '', $str);Orio. Link to comment https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/#findComment-73745 Share on other sites More sharing options...
simcoweb Posted August 12, 2006 Share Posted August 12, 2006 Ok, gotcha. I misunderstood your first post. I still would like to know the source of the HTML you're looking to strip. Is this coming via a database field or fields? Link to comment https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/#findComment-73746 Share on other sites More sharing options...
Orio Posted August 12, 2006 Share Posted August 12, 2006 My guess is it's being read from a file, no?Btw, try this:[code]<?phpwhile(ereg("<div>",$str)!==FALSE){$str=ereg_replace('<div align="center">(.*)</div>', '', $str);}echo $str;?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/#findComment-73749 Share on other sites More sharing options...
becu Posted August 12, 2006 Author Share Posted August 12, 2006 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 https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/#findComment-73762 Share on other sites More sharing options...
Jocka Posted August 12, 2006 Share Posted August 12, 2006 yea, when you read from the file, you can read by line and strip it out.Read this: http://us3.php.net/fileIt shows how to read each line. Link to comment https://forums.phpfreaks.com/topic/17345-how-to-replace-these-strings/#findComment-73773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.