Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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 - Fatal编程技术网

从变量php获取特定数据

从变量php获取特定数据,php,Php,感谢您的帮助$vari='爱是一种强烈依恋的情感。' affection and personal all of human kindness . '爱也是一种美德,代表“爱” . ' “同情、爱”; preg_match_all('@@',$vari,$matches); var_dump($matches[1]); 假设整个内容是一个正确转义的字符串,您可以使用此函数获取所有部分的数组 $vari='Love is an emotion of a strong <"/affectio

感谢您的帮助

$vari='爱是一种强烈依恋的情感。'
affection and personal
all of human kindness
. '爱也是一种美德,代表“爱” . ' “同情、爱”; preg_match_all('@@',$vari,$matches); var_dump($matches[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]);

或者使用正则表达式方法


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

这些引用需要转义才能成为有效的一行。(或者用单引号而不是双引号括起整个内容。)按原样,它会抛出一个错误。我想你只是想展示一下
$vari
的内容,而这不是一行实际的代码?
$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]);
<?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);

?>