当前位置: 动力学知识库 > 问答 > 编程问答 >

string - PHP pattern for replacment

问题描述:

I'm trying to replace this string

<img src="$post[avatarurl]" $post[avwidth] $post[avheight] alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" border="0" />

using PHP. I've tried using the full string as the patter, escaping things that needed to be escaped ect. I can not get this to even touch the img string -_-

if i do

$pattern = 'img';

$replacement = 'a';

that works fine.

so it has to be something to do with my pattern, maybe im not using an escape where I need to, I just need some help been working on this all day.

this is the last unsuccessful attempt I tried.

and i would love to keep it like this so the other img properties wouldn't matter and it finds everything between

<img src="$post[avatarurl]"

and its end />

$pattern = '/<img src="'.$post['avatarurl'].'"(.*?)>/';

$replacement = '<div id="myDiv">content</div>';

and i should note, im doing this as a str_replace

分享给朋友:
您可能感兴趣的文章:
随机阅读: