Discussion:
preg_replace
leam hall
2013-11-01 15:06:29 UTC
Permalink
Despite my best efforts to ignore preg_replace, it seems the best answer
for the current problem. That is, if I can get it to work...

Problem code:

$remove = "TAG000000-";
$replaceWith = "";
$newTitle = preg_replace($remove, $replaceWith, $title);

This, as well as using the $remove and $replaceWith as themselves and not
variables, gives:

PHP Warning: preg_replace(): Delimiter must not be alphanumeric or
backslash

Thoughts?

Leam
--
Mind on a Mission <http://leamhall.blogspot.com/>
Adam Szewczyk
2013-11-01 15:11:26 UTC
Permalink
Hi,
Despite my best efforts to ignore preg_replace...
Why? :)
PHP Warning: preg_replace(): Delimiter must not be alphanumeric or
backslash
Thoughts?
You are just using it wrong.
http://us2.php.net/manual/en/regexp.reference.delimiters.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
leam hall
2013-11-01 15:28:36 UTC
Permalink
uhh....okay, I feel mildly silly...especially since I use delimiters with
sed...

Adam, thanks!
Post by Adam Szewczyk
Hi,
Despite my best efforts to ignore preg_replace...
Why? :)
PHP Warning: preg_replace(): Delimiter must not be alphanumeric or
backslash
Thoughts?
You are just using it wrong.
http://us2.php.net/manual/en/regexp.reference.delimiters.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Mind on a Mission <http://leamhall.blogspot.com/>
Oussama Jilal
2013-11-01 15:22:29 UTC
Permalink
If you only want to replace the string 'TAG000000-', you can just use
'str_replace()' (no need to use regular expression).

http://php.net/manual/en/function.str-replace.php

If you DO want to use regular expression (with preg_replace()), then you
need to understand regular expressions first:

http://www.regular-expressions.info/
Post by leam hall
Despite my best efforts to ignore preg_replace, it seems the best answer
for the current problem. That is, if I can get it to work...
$remove = "TAG000000-";
$replaceWith = "";
$newTitle = preg_replace($remove, $replaceWith, $title);
This, as well as using the $remove and $replaceWith as themselves and not
PHP Warning: preg_replace(): Delimiter must not be alphanumeric or
backslash
Thoughts?
Leam
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
2013-11-01 15:33:10 UTC
Permalink
Post by leam hall
Despite my best efforts to ignore preg_replace, it seems the best answer
for the current problem. That is, if I can get it to work...
$remove = "TAG000000-";
$replaceWith = "";
$newTitle = preg_replace($remove, $replaceWith, $title);
This, as well as using the $remove and $replaceWith as themselves and not
PHP Warning: preg_replace(): Delimiter must not be alphanumeric or
backslash
Thoughts?
Leam
Can you offer a working example of the actual data you are working with and
what you expect to happen? Besides preg_replace, what have you tried and what
didn't work as expected?
--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
leam hall
2013-11-01 15:45:56 UTC
Permalink
Hey Jim,

The problem was tags. Most items had a tag "TAG00001", "TAG00002", etc.
Some had "TAG00000-SPECIAL001", "TAG000000-SPECIAL002". I was looking to
remove the "TAG00000-" bits. Using str_replace should take care of it.

Thanks!

Leam
Post by Jim Lucas
Post by leam hall
Despite my best efforts to ignore preg_replace, it seems the best answer
for the current problem. That is, if I can get it to work...
$remove = "TAG000000-";
$replaceWith = "";
$newTitle = preg_replace($remove, $replaceWith, $title);
This, as well as using the $remove and $replaceWith as themselves and not
PHP Warning: preg_replace(): Delimiter must not be alphanumeric or
backslash
Thoughts?
Leam
Can you offer a working example of the actual data you are working with
and what you expect to happen? Besides preg_replace, what have you tried
and what didn't work as expected?
--
Jim Lucas
http://www.cmsws.com/
http://www.cmsws.com/examples/
--
Mind on a Mission <http://leamhall.blogspot.com/>
Continue reading on narkive:
Loading...