【发布时间】:2019-01-16 19:00:40
【问题描述】:
试图改变“source.txt”中的这个字符串
<i data-duration="9.09">Text 1</i>
<i data-duration="11.08">Text 2</i>
<i data-duration="15.02">Text 3</i>
到这里:
00:00:00-->00:09:09
Text 1
00:09:09-->00:11:08
Text 2
00:11:08-->00:15:02
Text 3
<?php
if(isset($_POST['ok'])) {
$path = "source.txt";
$newstring = $_POST['teks'];
// Open source file
$source = fopen($path, 'w');
// replace with new html string
$new = str_replace($source,$newstring,$source);
fwrite($source,$new,strlen($newstring));
fclose($source);
$new = implode('<br />',file($path));
$search = '<i data-duration="';
// Split string with html tag $search
$firstExplode = explode($search, $new);
foreach ($firstExplode as $key) {
$secondExplode = explode('">', $key);
var_dump($secondExplode);
}
//Stuck
}
?>
请帮助我编写正确的程序,我坚持爆炸字符串。 CMIWW,我不了解 foreach 和访问数组的概念。
【问题讨论】:
-
看起来在客户端使用 JavaScript 做得更好
-
我该怎么办?
标签: php html string explode implode