This is what I have
$str = 'Just a <span class="green">little</span> -text åäö width 123#';
This is what I need
Results in spans and spaces, might be newlines as well.
$result = '<span></span><span></span><span></span><span></span> <span></span> <span class="green"><span></span><span></span><span></span><span></span><span></span><span></span></span> <span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span>';
You might wonder what I can possible be needing this for. I want to build a thing where ever character is represented by a block. Will look a bit like Defrag on Windows XP.
Question
- Replace every character with
<span></span>
. - Do not touch the HTML span that already exists in the string (might be hard?). There can be more than one HTML element.
- Do not touch spaces and newline.
- Regexp should do it? or Xpath?
What have I done so far?
I have found articles about the regexp but not replacing every character (excerpt space and newline)
$result = preg_replace("/???/", "<span></span>", $str);
print_r($result);