2012-07-13 102 views
-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"; 

查找從<開始的輸出「/並以/」>結尾。從變量php獲取具體數據

輸出:

affection and personal 
all of human kindness 

感謝您的幫助

+0

這些引號需要進行轉義爲它是一個有效的線。 (或者將整個事件用單引號括起來,而不是雙引號。)原來,它會引發錯誤。我想你只是想表明'$ vari'的內容是什麼,這不是一行實際的代碼? – Wiseguy 2012-07-13 03:52:13

回答

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]); 
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); 

?> 

或與正則表達式的方法。

我必須說,這是不是解決問題的最佳解決方案,但絕對是一個快速