For my text editor, I need to replace all new lines in any html link. I want all links to be formed correctly, that is. For instance this is a correct link: <a href="http://something.com"><img src="http://something.com/images/image.png" width="200" height="100"></a> Code (markup): But, let's say, if the same link looks something like this (notice how it has new lines): <a href="http://something.com"><img src="http://something.com/images/image.png" width="200" height="100"></a> Code (markup): I want those new lines to return to the original position. What preg_replace code can accomplish this? Thanks!
use Notepad++ and use it function Find & Replace \r\n Code (markup): and about 2nd Prob. use a If statement if it Contain or line Equal to...
Since everything that should be in quotes without breaks between them IS, why are you kvetching over something so silly? It's not like the one you're calling wrong or 'formed incorrectly' is invalid markup and perfectly fine. Hell, if i was writing that same code, I would INTENTIONALLY format it thus: <a href="http://something.com"> <img src="http://something.com/images/image.png" width="200" height="100" alt="Don't forget to describe the image!" /> </a> Code (markup): Since it's easier to read than the idiotic cramming of everything onto one line... which is how people make mistakes like skipping required attributes or not realizing you've declared the same thing more than once. (This is far more of an issue in CSS) Using any automated tool to change the formatting as you ask? Just going to make a absolute mess of the code -- of course if it doesn't have any proper indentation or sensible formatting you're already in that particular boat. In any case, there's NOTHING 'malformed' or 'incorrect' about the latter of your code blocks.
Since this is a PHP thread here's what might work... $stuff=str_replace(" \n"," ",$stuff); PHP: You will have to figure out if you have " \r" or " \r\n" in your file.
I'd assume he doesn't want to strip ALL linefeeds, just the ones inside elements like anchors, hence the asking about regex.
You are right, I want new lines in html links (between < and >) to be stripped. For instance I use this code to convert any quotation marks in links from symbols to real quotation marks: $text = preg_replace('/<([^<>]+)>/e', '"<" .str_replace(""", \'"\', "$1").">"', $text); Code (markup): Using the same concept, can you re-do this code and make it so that it would strip new lines in the html links? Thank you again.
The code you are saying above have no problem in using HTML and it will also work..you know HTML requires no formating and no case -senstive.
Wow, you guys are making everything SOOOOO complicated. So far I have been only lectured on what I should or shouldn't do. Ok, here's my question to some AWESOME php pro: Is there a preg_replace code that you know of that will replace new lines ONLY in HTML codes?? It should go like the one below but instead of replacing " it should replace new lines. Thank you for your help! [COLOR=#111111]$text = preg_replace('/<([^<>]+)>/e', '"<" .str_replace(""", \'"\', "$1").">"', $text); Code (markup): [/COLOR] Seriously, I need a solution to this thing, not lecturing.