简体   繁体   English

如何在PHP中的两个字符串之间替换特定的字符串

[英]How to replace specific strings between two strings in php

I would like to generate sql from this template : 我想从此模板生成sql:

select * from event where 
status_id = 'TOREPLACE_1' 
or status_id = 'TOREPLACE_2'
....

to have this result : 得到这个结果:

select * from event where 
status_id = (select id from name = 'TOREPLACE_1' limit 1)
or status_id = (select id from name = 'TOREPLACE_2' limit 1)
.....

the question is how to select the expression between '' after every status_id = 问题是如何在每个status_id =之后选择''之间的表达式

Thanks 谢谢

Use the following regexp: 使用以下正则表达式:

/status_id\s*=\s*\'([^\']+)\'/

The whole solution would require something like that: 整个解决方案将需要这样的东西:

preg_match_all($regexp, $string, $matches); 

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

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