PHP converting strings
===

Is there a way that I can convert these strings into html tags and vice versa

example:

$str = The^ff0000 quick brown^000000 fox jumps over the lazy dog.

the output must be

The<span style="color:#ff0000;"> quick brown</span> fox jumps over the lazy dog.

and vice versa