-1
$vari="Love is an emotion of a strong <"/affection and personal/"> attachment. Love is also a virtue representing <"/all of human kindness/">, compassion, and affection";

寻找从 <"/ 开始并以 /"> 结束的输出。

输出:

affection and personal
all of human kindness

感谢您的帮助

4

2 回答 2

1
$vari='Love is an emotion of a strong <"/affection and personal/"> attachment. '
   . 'Love is also a virtue representing <"/all of human kindness/">, '
   . ' compassion, and affection';
preg_match_all('@<"/(.*?)/">@', $vari, $matches);
var_dump($matches[1]);
于 2012-07-13T03:52:41.733 回答
0

假设整个内容是一个正确转义的字符串,您可以使用此函数获取所有部分的数组

<?php

function cutMultiple($start, $end, $from)
{
    $results = array(); // init the output
    $step1 = explode($start, $from);    // get the results

    for( $i = 1; $i<count($step1); $i++)
    {
        $outputs = explode($end, $step1[$i]);   // get final cut
        $results[] = $outputs[0];   // append the cut
    }

    return $results;
}

$text = 'Love is an emotion of a strong <"/affection and personal/"> attachment. Love is also a virtue representing <"/all of human kindness/">, compassion, and affection';

echo cutMultiple('<"/', '/">', $text);

?>

或者使用正则表达式方法。

我必须说这不是问题的最佳解决方案,但绝对是一个快速的解决方案

于 2012-07-13T03:56:03.603 回答