1

hello I want replace following phrase:

tinymce/jscripts/tiny_mce/plugins/emotions/img/smiley-cool.gif

with:

http://mysite.com/tinymce/jscripts/tiny_mce/plugins/emotions/img/smiley-cool.gif

I have tried :

$comments = preg_replace ("tinymce/", "http://mysite.com/tinymce/", $comments);

but i get an error:

warning Delimiter must not be alphanumeric or backslash

can you help me? thanks

4 Answers 4

2

The first parameter of preg_replace functions must be a regular expression (regex) delimited by a character of your choice. For example you should do :

$comments = preg_replace ("`tinymce/`", "http://mysite.com/tinymce/", $comments);

You may also use output buffering (with ob_start) to apply rewrite function on all url or anything you want.

http://fr.php.net/manual/en/function.ob-start.php

And try to match a real expression, here you could use str_replace, but if you write tinymce/ in a comment then it will be replaced too.

Sign up to request clarification or add additional context in comments.

Comments

2

preg_replace expects the first parameter to be a regular expression all regular expressions needs to be inside delimeters for example /regex/

so if you want your code to work you have to change your regex to /tinymce\// (and escape the forward slash) or use a different delimeter like @tinymce/@

Comments

1

Use str_replace.

$comments = str_replace ("tinymce/", "http://mysite.com/tinymce/", $comments);

just be very careful with this: It's a very primitive method. For example, if you run it twice, it will replace the occurrence in the already correct http://mysite.com/tinymce/, breaking the link in the process.

Comments

0

Read about basics of regular expressions in PHP (pattern has to begin and end with defined character ex. @ (after that come flags)) or use function str_replace

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.