Wednesday, 15 September 2010

php - preg_replace on require line -



php - preg_replace on require line -

trying maintain file name , remove other characters.

require_once($globals['root'] . '/library/test/testfactory.php');

want this:

/library/test/testfactory.php

so far have

$string = "require_once($globals['root'] . '/library/test/testfactory.php');" $string = preg_replace("~^.*?(?=\/)~i", "", $string);

i missing end characters of "');" help appreciated.

/library/test/testfactory.php');

update, on instance regex won't read don't have / in there.

require_once($_server['document_root'] . $this->config . 'display.php

i think want display.php

you can seek next both of cases.

$str = preg_replace('~^[^.]*\.[^\'"]*[\'"]([^\'"]+).*~m', '$1', $str);

working demo

php regex preg-replace

No comments:

Post a Comment