0

I habe a problems with PHP 5.3 and Joomla and error show like this preg_replace() [function.preg-replace]: Unknown modifier 'w' in /var/www/

My code

$params  = $this->item->params;
$images = json_decode($this->item->images);
$urls = json_decode($this->item->urls);
$canEdit    = $this->item->params->get('access-edit');
$user       = JFactory::getUser();

$imagesJson = json_decode($this->item->images);
$images_stringPath = substr($imagesJson->image_fulltext, 0,strripos($imagesJson->image_fulltext, '/'));
$path = "/".$images_stringPath;



$tmp_filename=preg_replace($_SERVER["DOCUMENT_ROOT"].$path.'/','',$value);
  • Why don’t you use `str_replace`? – Gumbo May 05 '13 at 07:07
  • Possible duplicate of [Warning: preg\_replace(): Unknown modifier '\]'](https://stackoverflow.com/questions/20705399/warning-preg-replace-unknown-modifier) – Toto Jul 04 '19 at 13:44

1 Answers1

0

Using preg_replace() for simple string replacement is overkill. Use str_replace() instead.

Anyhow, preg_replace() expects a regular expression pattern surrounded by "delimiters", which you didn't provide.

To go into detail, this is how your function call looks:

$tmp = preg_replace('/var/www/.../', '', $value);
//                   ^   ^^
//                   |   ||
//                   |   |+--- "modifier"
//                   |   +---- terminating delimiter
//                   +-------- starting delimiter

The starting delimiter would be the forward slash /. Which terminates the pattern after var. After the terminating delimiter, preg_replace() allows for optional modifiers. w is none of them.

Linus Kleen
  • 33,871
  • 11
  • 91
  • 99