Jump to content

Replace text, but not HTML code


eevan79

Recommended Posts

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) ?

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.