Rz Rasel Rz Rasel - 1 year ago 92
MySQL Question

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

I am storing HTML data in MySQL database for some reason. how to get all image,css and jss file src from MySQL data and change it to realpath.
Like to

Same as to

And to

Using preg_match or preg_replace in PHP

Answer Source

Try to run this regex


Using preg_replace it will be something like this:

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

But test it not in production code, but in your local testing environment as I didn't test it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download