Help - Search - Members - Calendar
Full Version: PHP: Correct way to format this preg_replace?
Invision Power Services > Community Forums > Community Web Design and Coding
Jeremy-
CODE
$html = preg_replace('/<!--access_key_desc:([a-z0-9]*)-->/ie', '<kbd title="'.str_replace("%", $1, $lang["access_key"]).'">{$1}</kbd>', $html);

I can not get that working for the life of me. I get this error:
QUOTE
Parse error[/b]: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in display.class.php on line 120

$lang['access_key'] is: Keyboard shortcut: Alt+% (Win), Ctrl+% (Apple)
(The % gets replaced with whatever the key is....)

Basically, what I am trying to do is have it so in my templates, someone can put in :
CODE
<!--access_key_desc:S-->earch

and that will change to:
CODE
<kbd title="Keyboard shortcut: Alt+S (Win), Ctrl+S (Apple)">S</kbd>earch
Michael K.
Get rid of the 'e' modifier, I believe. (It causes the replacement string to be evaluated as PHP code.)
_
Or use $1.
Jeremy-
CODE
$html = preg_replace('/<!--access_key_desc:([a-z0-9]*)-->/i', '<kbd title="'.str_replace('%', $1, $lang['access_key']).'">'.$1.'</kbd>', $html);


Still getting the same error. sad.gif
_
CODE
$html = preg_replace('/<!--access_key_desc:([a-z0-9]*)-->/ie', '<kbd title="str_replace('%', \$1, $lang['access_key'])">\$1</kbd>', $html);
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.