eevan79 Posted November 1, 2011 Share Posted November 1, 2011 I want to replace latin text to cirilic text. It's not so hard, but there is problem with HTML. It's also replaced. Example: $before = array("a","b","c","d"); //etc. $after = array("а","б","ц","д"); //etc. //final output *original: some text <a href="link"><img src="image" alt /></a> //final output *after: соме техт <а хреф="линк"><имг срц="имаге" алт /></а> How to replace all text but ignore HTML (not remove) ? Quote Link to comment https://forums.phpfreaks.com/topic/250244-replace-text-but-not-html-code/ Share on other sites More sharing options...
gizmola Posted November 1, 2011 Share Posted November 1, 2011 The way to handle this is to use http://www.php.net/manual/en/class.domdocument.php so that you can process the html as DOM nodes, and perform your translation only on the text. Depending on exactly what you are doing, this extension might be helpful: http://beerpla.net/projects/smartdomdocument-a-smarter-php-domdocument-class/ Quote Link to comment https://forums.phpfreaks.com/topic/250244-replace-text-but-not-html-code/#findComment-1284043 Share on other sites More sharing options...
eevan79 Posted November 1, 2011 Author Share Posted November 1, 2011 I already tried with DOM but without success. Maybe I need to look deeper... Also I found an interesting jQuery plugin, and maybe it can be usefull: http://benalman.com/code/projects/jquery-replacetext/examples/replacetext/ It replace all text but leave all tags and attributes untouched. Quote Link to comment https://forums.phpfreaks.com/topic/250244-replace-text-but-not-html-code/#findComment-1284063 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.