将所有代码放在一个函数中?
Place all code in one function?
这是原文
echo '<div style="float: right; width:31%; text-align: center; ">
<img src="/img/1.png" width="12" height="12"/><em> '.
$results['tagline']
.' </em></span><img title="'.
$results['tagline']
.' "src="/img/2.png" width="12" height="12" "> </div><br>';
所以 .$results['tagline'].
在哪里,我想用下面的代码替换
$string = ' '.$results['tagline'].' ';
$maxLength = 25;
if (strlen($string) > $maxLength) {
$stringCut = substr($string, 0, $maxLength);
$string = substr($stringCut, 0, strrpos($stringCut, ' '));
}
echo $string;
echo '<span style=""><span title2="'.$results['tagline'].'" class="masterTooltip">...</span></span>';
或者如果可以正确更正所有文本以使代码按我想要的方式工作!
哦,在这里,我应该指出 html 现在无效吗?
function title($t){
$string = ' '.$t.' ';
$maxLength = 25;
if (strlen($string) > $maxLength) {
$stringCut = substr($string, 0, $maxLength);
$string = substr($stringCut, 0, strrpos($stringCut, ' '));
}
$out= $string;
$out.= '<span style=""><span title2="'.$t.'" class="masterTooltip">...</span></span>';
return $out;
}
echo '<div style="float: right; width:31%; text-align: center; "><img src="/img/1.png" width="12" height="12" " /><em> '.title($results['tagline']).' </em></span><img title="'.$results['tagline'].'" src="/img/2.png" width="12" height="12" "> </div><br>';
这是原文
echo '<div style="float: right; width:31%; text-align: center; ">
<img src="/img/1.png" width="12" height="12"/><em> '.
$results['tagline']
.' </em></span><img title="'.
$results['tagline']
.' "src="/img/2.png" width="12" height="12" "> </div><br>';
所以 .$results['tagline'].
在哪里,我想用下面的代码替换
$string = ' '.$results['tagline'].' ';
$maxLength = 25;
if (strlen($string) > $maxLength) {
$stringCut = substr($string, 0, $maxLength);
$string = substr($stringCut, 0, strrpos($stringCut, ' '));
}
echo $string;
echo '<span style=""><span title2="'.$results['tagline'].'" class="masterTooltip">...</span></span>';
或者如果可以正确更正所有文本以使代码按我想要的方式工作!
哦,在这里,我应该指出 html 现在无效吗?
function title($t){
$string = ' '.$t.' ';
$maxLength = 25;
if (strlen($string) > $maxLength) {
$stringCut = substr($string, 0, $maxLength);
$string = substr($stringCut, 0, strrpos($stringCut, ' '));
}
$out= $string;
$out.= '<span style=""><span title2="'.$t.'" class="masterTooltip">...</span></span>';
return $out;
}
echo '<div style="float: right; width:31%; text-align: center; "><img src="/img/1.png" width="12" height="12" " /><em> '.title($results['tagline']).' </em></span><img title="'.$results['tagline'].'" src="/img/2.png" width="12" height="12" "> </div><br>';