使用php解析

发布于 2024-11-17 10:49:22 字数 932 浏览 4 评论 0原文

给定一个字符串:

[[Pulsatile_flow|pulsatile]] 血流的本质产生了脉搏 向下传播的波 [[动脉树]],并且在 [[主动脉_分叉|分叉]] 反射波反弹返回 半月瓣和起源 [[主动脉]]。这些返回波产生 这 [[重搏切迹#心室收缩|重搏 主动脉内显示切迹]] [[心脏期间的压力曲线 循环]]当这些反射波推动 在[[心脏瓣膜|主动脉半月形 瓣膜]].[[维基词典:主动脉|]]

我如何提取“[[ ]]”中包含的所有单词/短语,然后使用 php 将其放入数组中。

有条件: 如果“|”存在 只检索“|”之后的单词如果“|”后面没有单词检索“|”之前的单词但在“:”之后。
括号中的单词也将被忽略。

例如

[[aorta]]                              => retrieve aortal

[[Pulsatile_flow|pulsatile]]           => retrieve only pulsatile

[[Pulsatile_flow|pulsatile (temp)]]    => retrieve only pulsatile

[[Wiktionary:aorta|Aorta Topic]]       => retrieve Aorta Topic

[[Wiktionary:aorta|]]                  => retrieve aorta

[[aorta|]]                             => retrieve aorta

如果“|”不存在 检索全部

 [[维基词典:主动脉]] =>检索维基词典:主动脉

given a string :

The [[Pulsatile_flow|pulsatile]]
nature of blood flow creates a pulse
wave that is propagated down the
[[arterial tree]], and at
[[Aortic_bifurcation|bifurcations]]
reflected waves rebound to return to
semilunar valves and the origin of the
[[aorta]]. These return waves create
the
[[Dicrotic_notch#Ventricular_systole|dicrotic
notch]] displayed in the aortic
pressure curve during the [[cardiac
cycle]] as these reflected waves push
on the [[heart valve|aortic semilunar
valve]].[[Wiktionary:aorta|]]

how could i extract ALL words/phrases enclosed in '[[ ]]' and put then in an array using php.

with condition :
if "|" exist retrieve only words after "|" if no words exist after "|" retrieve the words before "|" but after ":" .
words in parenthesis will also be disregarded.

example

[[aorta]]                              => retrieve aortal

[[Pulsatile_flow|pulsatile]]           => retrieve only pulsatile

[[Pulsatile_flow|pulsatile (temp)]]    => retrieve only pulsatile

[[Wiktionary:aorta|Aorta Topic]]       => retrieve Aorta Topic

[[Wiktionary:aorta|]]                  => retrieve aorta

[[aorta|]]                             => retrieve aorta

if "|" did not exists retrieve all

 [[Wiktionary:aorta]]  => retrieve Wiktionary:aorta

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光无声 2024-11-24 10:49:22

看看这个:

$results = array();
$source = "The [[Pulsatile_flow|pulsatile]] nature of blood flow creates a pulse wave that is propagated down the [[arterial tree]], and at [[Aortic_bifurcation|bifurcations]] reflected waves rebound to return to semilunar valves and the origin of the [[aorta]]. These return waves create the [[Dicrotic_notch#Ventricular_systole|dicrotic notch]] displayed in the aortic pressure curve during the [[cardiac cycle]] as these reflected waves push on the [[heart valve|aortic semilunar valve]].[[Wiktionary:aorta|]]";
if ( preg_match_all('/\[\[(.*?)\]\]/is', $source, $matches) ) 
{
    foreach ( $matches[1] as $match ) 
    {
        if ( strpos( $match, '|' ) === false ) {
            $results[] = $match;
        } else {
            $parts = explode( '|', $match );
            if ( empty( $parts[1] ) ) {
                $parts = explode( ':', $parts[0] );
                $results[] = count( $parts ) == 2 ? $parts[1] : $parts[0];
            } else {
                $results[] = preg_replace( '/\(.*?\)/is', '', $parts[1] );
            }
        }
    }
}

var_dump( $results );

Check this out:

$results = array();
$source = "The [[Pulsatile_flow|pulsatile]] nature of blood flow creates a pulse wave that is propagated down the [[arterial tree]], and at [[Aortic_bifurcation|bifurcations]] reflected waves rebound to return to semilunar valves and the origin of the [[aorta]]. These return waves create the [[Dicrotic_notch#Ventricular_systole|dicrotic notch]] displayed in the aortic pressure curve during the [[cardiac cycle]] as these reflected waves push on the [[heart valve|aortic semilunar valve]].[[Wiktionary:aorta|]]";
if ( preg_match_all('/\[\[(.*?)\]\]/is', $source, $matches) ) 
{
    foreach ( $matches[1] as $match ) 
    {
        if ( strpos( $match, '|' ) === false ) {
            $results[] = $match;
        } else {
            $parts = explode( '|', $match );
            if ( empty( $parts[1] ) ) {
                $parts = explode( ':', $parts[0] );
                $results[] = count( $parts ) == 2 ? $parts[1] : $parts[0];
            } else {
                $results[] = preg_replace( '/\(.*?\)/is', '', $parts[1] );
            }
        }
    }
}

var_dump( $results );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文