Skip to main content
July 12, 2009
解決済み

php regex

  • July 12, 2009
  • 返信数 1.
  • 1659 ビュー

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

このトピックへの返信は締め切られました。
解決に役立った回答 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

David_Powers
David_Powers解決!
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

July 30, 2009

Hello,

sorry for re asking,

and if I need to delete the tag, but keeping the content?

example

<FONT FACE='arial' SIZE='12' COLOR='#000000' LETTERSPACING='0' KERNING='0'>content goes here</FONT>

will be plain text like "content goes here"

note, this html is flash html, but it doesn't mater, isn't it?

Thanks!

Pluda