Jump to content

Warning: preg_replace(): No ending delimiter '/' found

Recommended Posts


I'm sure my error isn't much, but I can't seem to remove part of a string... 

This is an example string:

Stack trace: 
#0 /mnt/HD/HD_a2/DATA/WWW/html/calchom/include/CorbeauPerdu/Database/DBWrapperStatement.php(525): CorbeauPerdu\Database\DBWrapperStatement->_stmtCommitOnEachExec_HOTFIX()
#1 /mnt/HD/HD_a2/DATA/WWW/html/calchom/include/CorbeauPerdu/Database/DBWrapperStatement.php(378): CorbeauPerdu\Database\DBWrapperStatement->_runMultiStatement(true)
#2 /mnt/HD/HD_a2/DATA/WWW/html/calchom/include/CorbeauPerdu/Database/DBWrapper.php(773): CorbeauPerdu\Database\DBWrapperStatement->runStatement(false, true)
#3 /mnt/HD/HD_a2/DATA/WWW/html/calchom/include/CorbeauPerdu/Database/DBWrapper.php(708): CorbeauPerdu\Database\DBWrapper->_storeDataEXE('INSERT INTO tbl...', Array, Array, true)
#4 /mnt/HD/HD_a2/DATA/WWW/html/calchom/test.php(112): CorbeauPerdu\Database\DBWrapper->storeData('INSERT INTO tbl...', Array, Array, true, true)
#5 {main}

I want to remove, in this case, all instances of "CorbeauPerdu\Database\" . These could be other words of course...

I tried the following regex in preg_replace(), which seems to work if I test in http://regex101.com/, but doesn't seem to work at all:

$pattern = "/\w+\\\w+\\/";
echo "Fixed = ".preg_replace($pattern, "", $str);

On top of that, my error log keeps telling me:

Warning: preg_replace(): No ending delimiter '/' found ...

Any ideas on what I'm doing wrong here? Much thanks :)



Edited by PatRoy
Link to post
Share on other sites
3 hours ago, requinix said:

regex101.com doesn't know that you're trying to put the regex into a PHP string.

Escape the backslashes.

Thanks. I had to escape 3 times the backslach afterall :  preg_replace("/\w+\\\/", "", $str);

Cheers for your help :)

Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.