Skip to main content
July 12, 2009
Answered

php regex

  • July 12, 2009
  • 1 reply
  • 1645 views

hello,

I need to replace my <div> tags to <TEXT> tag, but i'm very bad at regex...

i'm tring with this

<%div%[^>]*>(.*?)</%div%>

but it does not work, what can I do, to change <div align="left">my text</div>  to <TEXT align=left">my text</TEXT>

Thanks

Pluda

This topic has been closed for replies.
Correct answer David_Powers

You say PHP regex in the subject line, so I have written it for PHP. It's slightly different if you're using Find and Replace in Dreamweaver.

$text = <<<EOL
<div id="div1">Content for  id "div1" Goes Here</div>
<div id="div2">Content for  id "div2" Goes Here</div>
EOL;
$find = '{<div([\w\W]*?)</div>}';
$new = preg_replace($find, '<TEXT\1</TEXT>', $text);
echo $new;

1 reply

David_Powers
David_PowersCorrect answer
Inspiring
July 12, 2009

You say PHP regex in the subject line, so I have written it for PHP. It's slightly different if you're using Find and Replace in Dreamweaver.

$text = <<<EOL
<div id="div1">Content for  id "div1" Goes Here</div>
<div id="div2">Content for  id "div2" Goes Here</div>
EOL;
$find = '{<div([\w\W]*?)</div>}';
$new = preg_replace($find, '<TEXT\1</TEXT>', $text);
echo $new;

July 13, 2009

Hello,

thank you for reply, it solved my problem :-), I do not realy untherstand this regex things, but thei're a big, big help sometimes.

Thanks

Pluda

August 2, 2009

Are you doing this in PHP or in Dreamweaver? If you're doing it in Dreamweaver, you don't need a regex.

In the Find and Replace dialog box, select Search Specific Tag, and select font from the drop-down menu. Click the minus button to remove any conditions, and set the Action drop-down to Strip Tag.

If it's a regex you need, try this:

$pattern = '/<FONT[^>]*>([\w\W]+)<\/FONT>/i';

$stripped = preg_replace($pattern, '$1', $original);


hello, again, thanks for help

yes, I'm doing this in dreamweaver, but with php code, so ist's a regex I need.

yours, as usual works, but I don't untherstand it, please tell me, where in this patern is the content of the div, or text, or whatever?

example, I found this in internet

#</?FONT[^>]*>#is

you provided me this one

'/<FONT[^>]*>([\w\W]+)<\/FONT>/i'

yours uses /i, the other one uses #is