从变量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);
?>