preg_replace 时间和日期 link
preg_replace time and date with link
现有代码我绘制了一个txt文件,首先将http元素转换为链接,然后将hashtag元素转换为链接,然后打印结果。在每个文本的末尾是破折号,然后是时间和日期(DOY 和 YEAR 前导零 - 出于某种原因)。页面上的文本回显为 (ex.)
Blah blah blah and blah blah - 3:47:32 310 017
或time/date变体
14:09:47 23 017
7:38:839017
所以没有设定字数
$text = file_get_contents("temp.txt");
$link = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?)@', '<a href="" target="_blank"></a>', $text);
$hash = preg_replace('/(?<!\S)#([0-9a-zA-Z]+)/m', '<a href="https://duckduckgo.com/?q=" target="_blank">#</a>', $link);
echo $hash;
作为一个被承认的新手,我无法最好地翻译创建上述 preg_replace(s) 的全部语法来充分理解它以利用它来应用于想要对结尾 time/date 做同样的事情。我已经做了几次尝试,但没有看到任何结果来证明我什至正朝着正确的方向前进。
我的思路是顺序是
0?colon00colon00space0??space000
是要寻求的职位的身份。
您可以使用这个正则表达式:
$link = preg_replace('@\b(\d\d?:\d\d:\d\d [1-9]\d{0,2} 0\d\d)\b@', '<a href="" target="_blank"></a>', $text);
现有代码我绘制了一个txt文件,首先将http元素转换为链接,然后将hashtag元素转换为链接,然后打印结果。在每个文本的末尾是破折号,然后是时间和日期(DOY 和 YEAR 前导零 - 出于某种原因)。页面上的文本回显为 (ex.)
Blah blah blah and blah blah - 3:47:32 310 017
或time/date变体
14:09:47 23 017
7:38:839017
所以没有设定字数
$text = file_get_contents("temp.txt");
$link = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?)@', '<a href="" target="_blank"></a>', $text);
$hash = preg_replace('/(?<!\S)#([0-9a-zA-Z]+)/m', '<a href="https://duckduckgo.com/?q=" target="_blank">#</a>', $link);
echo $hash;
作为一个被承认的新手,我无法最好地翻译创建上述 preg_replace(s) 的全部语法来充分理解它以利用它来应用于想要对结尾 time/date 做同样的事情。我已经做了几次尝试,但没有看到任何结果来证明我什至正朝着正确的方向前进。
我的思路是顺序是
0?colon00colon00space0??space000
是要寻求的职位的身份。
您可以使用这个正则表达式:
$link = preg_replace('@\b(\d\d?:\d\d:\d\d [1-9]\d{0,2} 0\d\d)\b@', '<a href="" target="_blank"></a>', $text);