Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将$startOfLine指针移动到下一行的开头_Php_String - Fatal编程技术网

Php 将$startOfLine指针移动到下一行的开头

Php 将$startOfLine指针移动到下一行的开头,php,string,Php,String,但是如果我将1改为2,脚本将无法正常工作。有什么问题吗 $myText = "Hello\nworld\n" strpos ( $myText, "\n", 0); //Returns 5, which is also the length of the first line "Hello" 0+5+1; //Returns 6. It should be the index of the first character of the second line (w). But it's act

但是如果我将1改为2,脚本将无法正常工作。有什么问题吗

$myText = "Hello\nworld\n"

strpos ( $myText, "\n", 0); //Returns 5, which is also the length of the first line "Hello"
0+5+1; //Returns 6. It should be the index of the first character of the second line (w). But it's actually the index of the "n" right in front of it
strpos ( $myText, "\n", 6); //Returns 12
12-6   //Returns 6. This should be the length of the second line. But the second line actually contains 5 characters.
}
?>
原文:
对齐文本:

我认为您正在寻找文本的正当性

The quick brown fox<br />
jumped over the lazy<br />
dog.

输出:

敏捷的棕色狐狸
跳过懒惰的人
狗。
请注意\n和/n之间的区别正确的方法是\n指出它。现在更正了。我想我已经解决了这个问题。换行符“\n”被PHP计算为一个字符。我还没有做那么多。在继续之前,我想完全理解这个脚本。
}

?>

<h2>Original text:</h2>
<pre><?php echo $myText ?></pre>

<h2>Justified text:</h2>
<pre><?php echo $myTextJustified ?></pre>

</body>
</html>
<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");

echo $newtext;
?>
The quick brown fox<br />
jumped over the lazy<br />
dog.