Hi, I have an article stored in db with html tags. I want to apply target="_blank" for all the links that don't have target="_blank" in that article. Thanks in advance
15$ ... dude heres the free version If your html is in $text use this : $text = str_replace('<a href="','<a target="_blank" href="',$text); Code (markup):
if(!stripos($text,"target=\"_blank\"")) { $text = str_replace('<a href="','<a target="_blank" href="',$text); } PHP:
If your document is not frame based (which is a big no no in the first place), you should NEVER use target anyway. It is not in the strict HTML specification at all, and hacing it serves no discernable purpose.
The other reason for him using target="_blank" could be that he does not want people to leave his site when they click on that follows another site.
Okey I have asked using regex not using string functions, any way thanks for your suggestion, I have fixed the problem using regex.
how do you open up things in a new window then? Code (markup): Accessible Javascript. It is not part of the strict HTML standard and is therefore invalid HTML.
Perspective. Even if it's 'bad' HTML - If it's supported by all the browsers (and it is.) then whats wrong with it. I'm expecting a reply to this that this is 'Bad coding' and 'Bad standards' and it is. But target is a much more reliable way than javascript (which won't work if it's disabled.) This is the theory Google and other large companies use when coding their sites, they work on all browsers, but they don't meet standards. But so what, as long as you have the correct output - do standards really matter? Let's have a friendly debate. Dan