有人可以帮助我,我需要将变换字符串作为: 这是HTML代码:
<p><img src="/images/blog//023.jpg" alt="sposi a venezia" width="910" height="620" data-src="salvatorefranco.com/images/blog//023.jpg"; /><img src="/images/blog//wedding-photographer-in-portofino.jpg" alt="sposi a venezia" width="910" height="620" data-src="salvatorefranco.com/images/blog//…; /></p>
alt="" to
alt="title image"
我试过了:
$var = str_replace('alt=""', 'alt="'.$title_image.'"', $object);
但没有工作...... 谢谢 萨尔瓦多
答案 0 :(得分:0)
你可以这样做:
var watcher = new FileSystemWatcher();
watcher.Created += (sender, e) =>
{
var lines = File.ReadAllLines(e.FullPath, Encoding.UTF8); //io exception here
};
答案 1 :(得分:0)
您的代码应该可以正常运行。
<?php
$object = '<p><img src="/images/blog/023.jpg" alt="" width="910" height="620" data-src="/images/blog/023.jpg" /><img src="/images/blog//wedding-photographer-in-portofino.jpg" alt="" width="910" height="620" data-src="/blog//wedding-photographer-in-portofino.jpg" /></p>';
$title_image = "title image";
echo $var = str_replace('alt=""', 'alt="'.$title_image.'"', $object);
&GT;
输出
<p><img src="/images/blog/023.jpg" alt="title image" width="910" height="620" data-src="/images/blog/023.jpg" /><img src="/images/blog//wedding-photographer-in-portofino.jpg" alt="title image" width="910" height="620" data-src="/blog//wedding-photographer-in-portofino.jpg" /></p>
答案 2 :(得分:0)
我们可以尝试str_replace函数来解决这个问题
$alt='alt=""' ;
$var = str_replace("{$alt}", 'alt="title image"',"{$alt}");
echo $var;