Jump to content
#FlattenTheCurve ×
PatRoy

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

Recommended Posts

Posted (edited)

Hello, 

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 :)

Pat

 

Edited by PatRoy

Share this post


Link to post
Share on other sites

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

Escape the backslashes.

Share this post


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 :)

Share this post


Link to post
Share on other sites

The basic process is, if you want literal backslashes in a regex then you need to double it to make PCRE happy, then double it again to make PHP happy.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
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.