2017-03-08 10 views
0

私は数年前のプログラムを交換して、PHPとMySQLのデプロイメントを更新しています。preg_matcheregの構文が混乱しています。私はどこにでもスラッシュを入れようとしましたが、正しい構文を思いつくことはできません。私は何が欠けていますか?Preg_matchの構文

旧ライン:

if (!$this->config_allow_src_above_docroot 
    && !ereg('^'.preg_quote(str_replace($this->osslash, '/', realpath($this->config_document_root))), $AbsoluteFilename)) 
{ 

新ライン:

if (!$this->config_allow_src_above_docroot 
    && !preg_match('^'.preg_quote(str_replace($this->osslash, '/', realpath($this->config_document_root))), $AbsoluteFilename)) 
{ 

私の初心者くさいネスを言い訳してください、私は '/' をエスケープする必要がありますか?

答えて

1

あなたはpreg_*機能のために必要とされる区切り文字が欠落している:私は#を使用していたよう

preg_match('#^'.preg_quote(str_replace($this->osslash, '/', realpath($this->config_document_root))) . '#', $AbsoluteFilename) 
      ^                      ^

、スラッシュをエスケープする必要はありません。

+0

これはうまくいかないでしょうか? 〜($ this-> config_document_root))〜、$ AbsoluteFilename)){を使用して、($ this-> oslash、 '/'、realpath($ this-> config_document_root))){preg_moteチルダ? PHP構文解析エラーが発生しました:予期しない構文エラー ')' – SL0WLearner

+0

@ SL0WLearner区切り文字は正規表現文字列の一部です。文字列の外側に文字を追加することはできません。 – jeroen

+0

まだ私には多すぎる括約があると私に伝えています。 '〜'、$ AbsoluteFilename))$ this-> config_allow_src_above_docroot &&!preg_match( '〜^')preg_quote(str_replace($ this-> osslash、 '/'、realpath($ this-> config_document_root))) { – SL0WLearner