简体   繁体   English

如何搜索文本并替换为preg_replace?

[英]How to search for text and replace with preg_replace?

I want to check if the text exists: 250000 Using preg_replace or preg_match, then replace it to appear like this: 我想检查文本是否存在:250000使用preg_replace或preg_match,然后将其替换为如下所示:

260000 260000

Basically this is supposed to be an hour and a day (25 00:00:00) I want to check if it is midnight then the text will be replaced with the next day's date. 基本上应该是一个小时和一天(25 00:00:00),我想检查一下是否是午夜,然后将文本替换为第二天的日期。

What I tried: 我试过的

$text = "today250000";
//I need to add the line with the text that I want ($newday0000), but I do not know how
$newday = date("d", strtotime('tomorrow'));

preg_replace($text, $replace, $day);
echo $day;

I tried also: 我也尝试过:

if(strpos($text, '250000'..

But it was not stable and it changed most of the hours in my txt file 但是它不稳定,并且在我的txt文件中大部分时间都发生了变化

<?php echo preg_replace($text, $replace, $day); ?>

如果您仅“ echo $ day”,则什么也没有替换,只是回声天数没有preg_replace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM