Xeoncross Posted July 11, 2007 Share Posted July 11, 2007 Hello everyone! Today I am having fun trying to get another element in or around a blockquote so I can have two CSS elements to work with. (like having a start and end quote image behind my quotes). So I want to add a "DIV" either before or after my blockquote - I am just having some weird happenings... I thought that str_replace would work but it gives really weird results with the added div in another area of the text. Can anyone help me with this? <?php //This is a small version of the text: $text = '....</p><blockquote><p>This is the text</p><p>This is the text</p></blockquote><p>....'; First I tried this: $text = str_replace('<blockquote>', '<div class="blockquote"><blockqoute>', $text); $text = str_replace('</blockquote>', '</blockquote></div>', $text); print $text; ?> That gave me the following: <div class="blockquote"><blockqoute></blockqoute><p>...</p><p>... And ...</p></div> So then I went for some preg_replace and here is the code: <?php //This is a small version of the text: $text = '....</p><blockquote><p>This is the text</p><p>This is the text</p></blockquote><p>....'; $text = preg_replace('/<blockquote>^(.*?)$<\/blockquote>/', '<div class="blockquote"><blockquote>\\1</blockquote></div>', $text); print $text; ?> Which gave me this: <blockquote><p>...</p><p>...and ...</p></blockquote> As you can see my regex code isn't working and the str_replace is just nuts. So I need some help - Thanks! Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 11, 2007 Share Posted July 11, 2007 I don't know if this will work for you in this case, but do you know about the :before and :after pseudo-elements? (http://www.w3.org/TR/CSS21/selector.html#before-and-after) Incidentally, your code works for me: <?php $text = '....</p><blockquote><p>This is the text</p><p>This is the text</p></blockquote><p>....'; echo htmlentities($text),"\n"; $text = str_replace('<blockquote>', '<div class="blockquote"><blockquote>', $text); $text = str_replace('</blockquote>', '</blockquote></div>', $text); echo htmlentities($text),"\n"; ?> OUTPUT: ....</p><blockquote><p>This is the text</p><p>This is the text</p></blockquote><p>.... ....</p><div class="blockquote"><blockquote><p>This is the text</p><p>This is the text</p></blockquote></div><p>.... Quote Link to comment Share on other sites More sharing options...
Xeoncross Posted July 11, 2007 Author Share Posted July 11, 2007 Well, I found out that the str_replace WAS working - just Firefox was saying that the code was incorrect (see below) and was closing the blockquote for me! What the filp?! ...</p><p><div class="blockquote"><blockqoute></p><p>...</p><p></blockquote></div></p><p>... (View page) ...</p><p><div class="blockquote"><blockqoute></blockquote></p><p>...</p><p></div></p><p>... (View selection) I can't believe that Firefox is messing with a page's code and then showing you the what IT says should be on a page!!!! Agh!!!!! SO anyways, now I need to delete the <p> and </p> that is around the blockquote so that it will be "valid". I am trying this now to fix the problem: <?php $text = preg_replace('/(<p>)?<(\\?)blockquote>(<(\\?)p>)?/', '<$2blockquote>', $text); ?> But it doesn't work Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 11, 2007 Share Posted July 11, 2007 You were spelling <blockquote> like <blockqoute> in your earlier example, which is probably why FireFox couldn't find the tag. Quote Link to comment Share on other sites More sharing options...
Xeoncross Posted July 11, 2007 Author Share Posted July 11, 2007 You were spelling "blockquote" like "blockqoute" in your earlier example, which is probably why FireFox couldn't find the tag. Wow, yep your right - I just spent all day on this because I never learned how to spell in sckool. this is sad..... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.