简体   繁体   English

php函数strpos和substr在localhost和服务器中的不同结果

[英]different results for php functions strpos and substr in localhost and server

suppose we have strings like "adjkadahsdjashd##kjhkhkjhkjhs" . 假设我们有类似“ adjkadahsdjashd ## kjhkhkjhkjhs”之类的字符串。 and I want to cut them to for example adjkadahsdjashd and kjhkhkjhkjhs 我想将其剪切为adjkadahsdjashd和kjhkhkjhkjhs

so I wrote this on my computer : 所以我在计算机上写了这个:

<?php
$s="508462170##dfsfgdfggf";
echo substr($s,strpos($s,"#")+2)."</br>";
echo substr($s,0,strpos($s,"#"));
?>

and the result is okay , but when I upload this to server , it returns me nothing . 结果没问题,但是当我将其上传到服务器时,它什么也没返回。

server php version is 5.2.17 服务器php版本是5.2.17

:( :(

尝试回显strpos()的结果以缩小问题范围。

An shorter way for your problem would be: 解决问题的更简单方法是:

echo implode('<br/>', explode('##', $s));

did this work on booth platforms. 在展位平台上做了这项工作。

Also </br> is not valid HTML. </br>也是无效的HTML。

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

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