字符串标签和从输出重新排列顺序

时间:2017-08-15 08:30:20

标签: php curl strip

我如何从下面的$("#myId").attr("aria-controls", myValue); 输出中删除" -<b>标记?我试过curl,但后来我不知道如何重新安排订单

strip_tags

卷曲输出

<?php
$ch = curl_init("http://beta.test123.com/archive.csv?s=BLOGS&f=lc1");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_exec($ch);
curl_close($ch);
?>

尝试实现以下格式,输出到blog.inc文件

"4:01pm - <b>n1234</b>",+0.50

2 个答案:

答案 0 :(得分:1)

$result = strip_tags($out);
$result = str_replace(["- ", '"'], '', $result); // remove unnecessary chars
$result = str_replace(',',' ', $result); // change comma to space for explode
$array = explode(' ', $result); // explode by space

//here result - array with needed values
$array[1] // should be n1234
$array[0] // should be 4:01pm
$array[2] // should be +0.50

答案 1 :(得分:1)

也许是这样的?
我使用regex来获取字符串的部分,并使用strip_tags()删除粗体标记。

要将商品重新排列到您的订单,请使用array_shift()

$str = '"4:01pm - <b>n1234</b>",+0.50';

preg_match('/\"(.*?)\s-\s(.*?)\",(.*)/', strip_tags($str), $matches);
unset($matches[0]); // unset [0] because that is the full match.
$matches[] = array_shift($matches); // takes first item and makes it last.

echo implode("<br>\n", $matches);
//var_dump($matches);

输出:

n1234
+0.50
4:01pm

https://3v4l.org/smQIV

EDIT;我现在看到你想要“4:01 PM ”和空格。不确定它是否是拼写错误但是下面的代码应该会发生这种情况,只需在内爆之前添加它。

$matches[2] = date("g:i A", strtotime($matches[2]));