I've tried to create a regular expression to search only images that not contain a specified class, but the server gives me 0 error unexpected '/' separator.
$regex = '/<img((?!(.*?)class=['\"](.*?)nopopup(.*?)['\"](.*?)).*?>/';
Now my code is the next, I need that preg_match work only in images that not contain class nopopup
$regex = '/<img.*?>/';
$createImageLink = function($imageTag)
{
preg_match('/src="([^"]*)"/i', $imageTag[0], $results);
$srcAttribute = $results[0];
$srcUrl = explode("=", $srcAttribute);
return '<a href=' . $srcUrl[1] . ' class="magnific_popup">'.$imageTag[0].'</a>';
};
if (isset($article->text))
{
$article->text = preg_replace_callback($regex, $createImageLink, $article->text);
$article->text .= '<script> jQuery( document ).ready(function() { jQuery(".magnific_popup").magnificPopup({ type: "image", enableEscapeKey:true }); });</script>';
}
if (isset($article->text))
{
$article->introtext = preg_replace_callback($regex, $createImageLink, $article->introtext);
$article->introtext .= '<script> jQuery( document ).ready(function() { jQuery(".magnific_popup").magnificPopup({ type: "image", enableEscapeKey:true }); });</script>';
}
break;
Where is the error?