在PHP中使用preg_match或preg_replace将MySql数据库数据格式化或更改为realpath


Format or change MySql database data to realpath using preg_match or preg_replace in PHP

出于某种原因,我在MySQL数据库中存储HTML数据。如何从MySQL数据中获取所有图像,css和jss文件src并将其更改为realpath。Like to

相同

使用preg_match或preg_replace

尝试运行这个正则表达式

/(?:src|href)="(.*?)"/g

使用preg_replace将会像这样:

preg_replace('/(?:src|href)="(.*?)"/g', 'http:localhost/$1', 'Your field in database');

但是不要在生产代码中测试,而是在您的本地测试环境中测试,因为我没有测试它。