This question is related to a previous question but requires a refinement that I need help with.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23491772.html
Problem: I am reading in a language file and updating it online and need to preserve the file formatting.
Mostly working except for situation with quotes in the replacement text.
I need a preg_replace that will update the one line searching on an array key ($token) + (n number of spaces or tabs) + '==>' + (n number of spaces or tabs) and replace it with the same formatting except with my new 'string here'.
Example array in file:
$LANG_MGE07 = array (
'search_message' => 'Searched for the phrase \'%s\'. Found %s items (%s seconds).',
'member_profile_pagetitle'
=> 'Member profile for:',
'watch_default_pagetitle' => 'Watch Content - Home page',
'watch_series_pagetitle' => 'Watch Content - Series View',
'watch_episodes_pagetitle'
=> 'Watch Content - Episodes View',
'no_search_results' => 'No results found matching your search request'
);
A more extreme example:
'register_failed_message' => '<span style="color:red">The username or email you\\\'ve provided are already in use. Please try again...</span>',
The existing function in my class that works fine (thanks Roonaan) except in the condition where the replacement text has quotes - escaped.
function updateToken($token, $newvalue)
{
$this->_content = preg_replace('#(\''.preg_q
uote($toke
n).'\'\s+=
>\s+)\'[^\
']+\'#i', '$1\''.$newvalue.'\'', $this->_content);
}
Can this be resolved ?
Thanks!