Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.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列出标题_Php_Html_Regex - Fatal编程技术网

类似维基百科的索引,用PHP列出标题

类似维基百科的索引,用PHP列出标题,php,html,regex,Php,Html,Regex,我试图制作一个php函数,将我的所有标题转换为链接列表。我目前的做法是用preg_替换来完成这项工作 $txt = preg_replace("#\[h1\](.+?)\[/h1\]#is", "<h2 style='display:inline;'>\\1</h3>", $txt); $txt = preg_replace("#\[h2\](.+?)\[/h2\]#is", "<h3 style='display:inline; '>\\1</

我试图制作一个php函数,将我的所有标题转换为链接列表。我目前的做法是用preg_替换来完成这项工作

    $txt = preg_replace("#\[h1\](.+?)\[/h1\]#is", "<h2 style='display:inline;'>\\1</h3>", $txt);
$txt = preg_replace("#\[h2\](.+?)\[/h2\]#is", "<h3 style='display:inline; '>\\1</h4>", $txt);

不是很清楚,但你能试试这个吗:

$txt = preg_replace("#\[h2\](.+?)\[/h2\](.+?(?=\[h1\]|\[h2\])|.+$)#is", "<h2 style='display:inline;'>\\1</h2>", $txt);
$txt = preg_replace("#\[h1\](.+?)\[/h1\](.+?(?=\[h1\]|<h2)|.+$)#is", "<h1 style='display:inline;'>\\1</h1>", $txt);
$txt=preg\u replace(“\[h2\](.+?)\[/h2\](.+?(?=\[h1\]\[h2\])).+$)\[is'、“\\1”、$txt);

$txt=preg\u replace(“\[h1\](.+?)\[/h1\](.+?(?=\[h1\])”你所说的“但我似乎无法让其余部分消失”是什么意思?其余部分是什么?像
文本标题文本标题文本文本文本
应该变为
标题
(其中有一些li标记,但这应该很容易实现。)但是你要替换成:/哦,是的,那只是因为它们有点大,我想试试。你可以忽略这一点。这在这个例子中效果很好,但在其他情况下不起作用。(我可能一直很模糊,但那是因为我今晚没睡。对不起。:P)有任意数量的[h1]和[h2]以半随机顺序排列。(基本上是一个[h1],下面是x[h2],后面是一个新的[h1],就像wiki上的内容列表一样:)现在怎么样?也许你只需要删除文本直到第一个H1如果你第一次改成
  • 你能再给我一次你看的文本吗?喜欢并且有效,但是你需要在href内添加双引号,然后添加las并删除第一个。将这两个替换都改成此href=\“\\\1>改成此href=\“\\\\1\”>
    $txt = preg_replace("#\[h2\](.+?)\[/h2\](.+?(?=\[h1\]|\[h2\])|.+$)#is", "<h2 style='display:inline;'>\\1</h2>", $txt);
    $txt = preg_replace("#\[h1\](.+?)\[/h1\](.+?(?=\[h1\]|<h2)|.+$)#is", "<h1 style='display:inline;'>\\1</h1>", $txt);