我觉得这应该是一个如此简单的“更改逗号”,所以我已经完成了我的研究并尝试了许多不同的东西,但似乎没有任何效果。首先是我用来调试它的代码:
/* More code before */
$Test = "This is a test <ul>TEST</ul> Blabla";
$Real = $Data['chapters']['introduction'];
var_dump($Real);
echo "\n\n";
preg_match('/<ul>(.*)<\/ul>/', $Test, $VarTest);
var_dump($VarTest);
echo "\n\n";
preg_match('/<ul>(.*)<\/ul>/', $Real, $VarReal);
var_dump($VarReal);
结果是这样的:
string(1888) "<p>The <b>theory of relativity</b>, or simply <b>relativity</b>, generally encompasses two theories of <a href="http://en.wikipedia.org/wiki/Albert_Einstein" title="Albert Einstein">Albert Einstein</a>: <a href="http://en.wikipedia.org/wiki/Special_relativity" title="Special relativity">special relativity</a> and <a href="http://en.wikipedia.org/wiki/General_relativity" title="General relativity">general relativity</a>. Concepts introduced by the theories of relativity include:</p>
<ul>
<li>
<p>Measurements of various quantities are <i>relative</i> to the velocities of observers. In particular, space and time can <a href="http://en.wikipedia.org/wiki/Time_dilation" title="Time dilation">dilate</a>.</p>
</li>
<li>
<p><a href="http://en.wikipedia.org/wiki/Spacetime" title="Spacetime">Spacetime</a>: space and time should be considered together and in relation to each other.</p>
</li>
<li>
<p>The speed of light is nonetheless invariant, the same for all observers.</p>
</li>
</ul>
<p>The term "theory of relativity" was based on the expression "relative theory" (<a href="http://en.wikipedia.org/wiki/German_language" title="German language">German</a>: <span lang="de"><i>Relativtheorie</i></span>) used by <a href="http://en.wikipedia.org/wiki/Max_Planck" title="Max Planck">Max Planck</a> in 1906, who emphasized how the theory uses the <a href="http://en.wikipedia.org/wiki/Principle_of_relativity" title="Principle of relativity">principle of relativity</a>. In the discussion section of the same paper <a href="http://en.wikipedia.org/wiki/Alfred_Bucherer" title="Alfred Bucherer">Alfred Bucherer</a> used for the first time the expression "theory of relativity" (<a href="http://en.wikipedia.org/wiki/German_language" title="German language">German</a>: <span lang="de"><i>Relativitätstheorie</i></span>).</p>
"
array(2) {
[0]=>
string(13) "<ul>TEST</ul>"
[1]=>
string(4) "TEST"
}
array(0) {
}
关于为什么最后一个数组为空的任何想法(当它应该包含 3 个列表元素时)?
更多信息,它是使用 PDO 从 MySQL 检索的,我尝试转义它(对于引号),替换引号,检查此文本大小是否低于 preg_match() 字符串限制,我只是找不到问题是。我认为代码本身就说明了问题所在,无论如何,我很乐意执行您需要的测试。谢谢。