繁体   English   中英

PHP的str_replace返回空字符串

[英]php str_replace returns empty string

<?php

$html = '<form id="form1" name="f1" action="/jk" dummy';

$html = str_replace(
    '<form id="form1" name="f1"',
    '<form id="form1" name="f1" xxxxxxxxxxxxx',
    $html);

echo $html;

为什么结果为空?

我正在使用PHP 5.3.27(CLI)

谢谢。

$html = '<form id="form1" name="f1" action="/jk" dummy';
$html = str_replace(
    '<form id="form1" name="f1"',
    '<form id="form1" name="f1" xxxxxxxxxxxxx',
    $html);

echo highlight_string($html, true);

另一种显示方式是:

header("Content-Type: text/plain");
echo $html;

试试这个方法

<?php
echo 'hello<br>';
$html = "abcde<br>";
echo $html;
$a = substr_replace($html,
    'xyzhi',
    0);

echo $a;
?>

Str_replace将需要您要从字符串中替换的单词。我希望这可以工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM