I have to show source code, but want to remove database information. The info is stored this way
'db.host' => 'localhost',
'db.user' => 'user',
'db.pass' => 'pass',
'db.name' => 'name
right now I got this as regex, but it doesnt seem to work
$content = preg_replace('\'db.host\' => \'(.*)\'/', '', $content);
Error:
Warning: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier '='
You're not getting the string properly, try this
$content = preg_replace("/'db.[a-z]+' => '(.*?)'/i", '', $content);
Have a look at my example: http://regexr.com?36js6
You can use:
$s = <<< EOF
'db.host' => 'localhost',
'db.user' => 'user',
'db.pass' => 'pass',
'db.name' => 'name'
EOF;
echo preg_replace("~(=>\s*')[^']+'~m", '$1****\'', $s);
OUTPUT
'db.host' => '****',
'db.user' => '****',
'db.pass' => '****',
'db.name' => '****'
You're missing the first forward-slash (opening delimiter).
$result = preg_replace('/\'db.host\' => \'(.*)\'/', '', $subject);
^