我真的一点也不卡在这里,因为我不擅长正则表达式,..我认为它真的很棘手,所以我正在寻求帮助:)
我的问题
foo = "bar"
$bar = foo
foo()
$foo = bar;
bar = foo() {}
$foo = array();
应该匹配:
foo = "bar" -> match foo not bar
$bar = foo -> match foo not bar
foo() -> no match
$foo = bar; -> match bar not foo
bar = foo() {} -> match bar not foo
$foo = array(); -> no match
它应该匹配所有没有引号且不以 $ 开头或以 ( 结尾的单词 A-Za-z0-9_
非常感谢您的每一个帮助!
编辑:
一个小例子来更好地解释我试图实现的目标:
<?php
/**
* little script to explain better what im trying to achieve
*/
echo "\nSay Hi :P\n=========\n\n";
$reply = null;
while ("exit" != $reply) {
// command
echo "> ";
// get input
$reply = trim( fgets(STDIN) );
// last char
$last = substr( $reply, -1 );
// add semicolon if missing
if ( $last != ";" && $last != "}" ) {
$reply .= ";";
}
/*
* awesome regex that should add $ chars to words
* to make using this more comfortable!
*/
// output buffer
ob_start();
eval( $reply );
echo $out = ob_get_clean();
// add break
if ( strlen( $out ) > 0 ) {
echo "\n";
}
}
echo "\n\nBye Bye! :D\n\n";
?>
问候马里奥