ALWAN ALWAN - 12 days ago 5
MySQL Question

How to replace specific strings between two strings in php

I would like to generate sql from this template :

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 =

Thanks

Answer

Use the following regexp:

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

The whole solution would require something like that:

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