0

我有一个以下变量变量

$test="<title>This is 1 test | "best"</title>, <title>This is 2 test | "best"</title>,     <title>This is 3 test | "best"</title>, <title>This is 4 test | "best"</title>, <title>This is 5 test | "best"</title>";

我希望数据按以下顺序排列,通过使用数组并从头开始 获取“标题”和最后的“最佳”/标题

This is 1 test
This is 2 test 
This is 3 test 
This is 4 test 
This is 5 test 

谢谢和亲切的问候,

4

2 回答 2

0
$test='<title>This is 1 test | "best"</title>, <title>This is 2 test | "best"</title>,     <title>This is 3 test | "best"</title>, <title>This is 4 test | "best"</title>, <title>This is 5 test | "best"</title>';    
$array = explode(' , ', trim(str_replace(array('"best"', '|'), '', strip_tags($test))));
print_r($array);

键盘

于 2012-07-13T02:48:19.820 回答
0

首先,变量$test无效,您需要将其中的双引号转义或使用单引号作为值。

<?php
$test = '<title>This is 1 test | "best"</title>, <title>This is 2 test | "best"</title>,     <title>This is 3 test | "best"</title>, <title>This is 4 test | "best"</title>, <title>This is 5 test | "best"</title>';

$test = str_replace(array('<title>', '| "best"</title>'), array('',''), $test);

$array = explode(", ", $test);

print_r($array);
于 2012-07-13T02:50:52.553 回答