【问题标题】:error: A non well formed numeric value encountered错误:遇到格式不正确的数值
【发布时间】:2013-11-15 05:11:27
【问题描述】:
while ($strpos = strpos($text, $search, $offset)) {
        $offset = $strpos + $search_length .'<br>'; 
        $text = substr_replace($text, $replace, $strpos, $search_length);
    }

注意:在第 13 行的 C:\xampp..\index.php 中遇到格式不正确的数值

第 13 行是:while ($strpos = strpos($text, $search, $offset)) {

这是我定义变量的方式:

$text = $_POST['text'];
$search = $_POST['searchfor'];
$offset = 0;

实在是找不到哪里出错了。

代码现在运行良好,无法解释之前究竟发生了什么。谢谢你的回复。

【问题讨论】:

  • 我会echo这些变量;那么问题就很明显了
  • 好吧,将 '&lt;br&gt;' 添加到原本数字的 $offset 变量对您没有任何帮助
  • @Phil - 想解释一下&lt;br&gt; 的添加位置/方式?
  • @Floris Err,第 2 行 - $offset = $strpos + $search_length .'&lt;br&gt;';
  • 啊-它发生在第二遍...我看着offset=0;并努力理解你在说什么。您显然已经确定了解决方案 - 即数字 $offset 格式错误的地方(字符串......)。请写下答案,这样我们就可以重新开始我们的生活了。

标签: php non-well-formed


【解决方案1】:

尝试将其更改为:

while ($strpos = strpos($text, $search, $offset) !== false) {
 ...
}

【讨论】:

  • @Floris 不,PHP 将首先评估比较左侧的语句
【解决方案2】:

不要与&lt;br&gt; 连接。在下一条语句中回显 br。错误会消失

while($strpos = strpos($text, $search, $offset))  {

    echo $offset= $strpos+$search_length;
    echo '<br>';

        }

我不喜欢回显一个新行,但如果我使用$search_length。出现br 标签错误。我不知道为什么。

【讨论】:

    猜你喜欢
    • 2019-11-17
    • 1970-01-01
    • 2011-09-26
    • 2017-09-13
    • 2014-09-18
    相关资源
    最近更新 更多