douxian5076
2017-05-05 08:14
浏览 85
已采纳

explode和substr_count不能与“ ”一起使用

Hi guys why i can't explode or count character with " " in my string?

$input = 'sv_privateClientsForClients\\0\\sv_pure\\0
0 0 0 0 999 \"DarkGhost\"\"spectator\"

0 0 0 0 999 \"MaximuM\"\"spectator\"

",';

$str = substr($input, strpos($input, "sv_pure") + 11, -7);

$x = explode('

', $str);    //not work
$c = substr_count($str,"

"); // not work

图片转代码服务由CSDN问答提供 功能建议

大家好,为什么我不能在我的字符串中用“ ”爆炸或计算字符?

  $ input ='sv_privateClientsForClients \\ 0 \\ sv_pure \\ 0 
0 0 0 0 999 \“DarkGhost \”\“spectator \”
 
0 0 0 0 999  \“MaximuM \”\“观众\”
 
“,'; 
 
 $ str = substr($ input,strpos($ input,”sv_pure“)+ 11,-7); 
 
  $ x = explode('
 
',$ str); //不工作
 $ c = substr_count($ str,“
 
”); //不工作
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douye2572 2017-05-05 08:23
    已采纳
    $input = 'sv_privateClientsForClients\\0\\sv_pure\\0
    0 0 0 0 999 \"DarkGhost\"\"spectator\"
    
    0 0 0 0 999 \"MaximuM\"\"spectator\"
    
    ",';
    $str = substr($input, strpos($input, "sv_pure") + 11, -7);
    $x = explode('
    
    ', $str);   
    $c = substr_count($str,'
    
    '); //changed double quotes to single quotes
    
    点赞 打赏 评论
  • doulu3865 2017-05-05 08:46

    Try to replace ' ' with a "ABC" using str_replace() function and then explode string with "ABC"

    点赞 打赏 评论
  • douchun1961 2017-05-05 08:48

    Do you want a pair of newline characters, or do you literally want the string in the output? The answer hinges on the answer to that question, but in either case by far the most important thing you can do is be consistent with the style of quotes you use.

    PHP strings can be in single quotes (''), or in double quotes ("") as well as a couple of other formats that we won't get into for the sake of simplicity. Single quotes and double quotes are not the same:

    • Double quote strings support the inclusion of a number of control characters ( for newlines, \t for tabs, etc), while single quote strings support almost no control characters. If you want a newline in a single quote string you have to literally put a newline into the string.
    • Double quote strings support variable substitution (if you put a named variable in the string then the contents of the named variable will be substituted when you echo the string out).

    The fact that your code is using single-quoted strings for some things and double-quoted strings for others means that your strings are inconsistent. " " will not match ' ' because they are not the same thing.

    If you intend for to mean a pair of newlines then you should simply just use double-quoted strings throughout.

    If you intend for to mean the literal string ' ' then you can either use single-quoted strings throughout, or you could use the escape sequence \\ which tells PHP that the next character is not a control character but a literal backslash. To get with a double-quoted string you need to enter it into your code as "\ \ "

    点赞 打赏 评论

相关推荐 更多相似问题