Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
API page: https://api.drupal.org/api/drupal/modules%21filter%21filter.api.php/func... and https://api.drupal.org/api/drupal/modules%21filter%21filter.api.php/func...
$text = preg_replace('|<code>(.+?)
|se', "[codefilter_code]$1[/codefilter_code]", $text);
The e option is deprecated in PHP 5.5, and removed in PHP 7. (Also, it doesn't do anything in the example.)
Comments
Comment #2
joachim CreditAttribution: joachim commentedComment #3
rashid_786 CreditAttribution: rashid_786 commentedAccording to you it should be without 'e' option like the following line?
$text = preg_replace('|<code>(.+?)
|s', "[codefilter_code]$1[/codefilter_code]", $text);Comment #4
joachim CreditAttribution: joachim commentedYup, that looks fine. The 'e' option wasn't doing anything anyway, since the replacement parameter isn't executable code.
Comment #5
shashikant_chauhan CreditAttribution: shashikant_chauhan as a volunteer and at Iksula commentedadding patch.
Comment #6
shashikant_chauhan CreditAttribution: shashikant_chauhan as a volunteer and at Iksula commentedComment #8
Sutharsan CreditAttribution: Sutharsan commentedComment #9
lhuria94 CreditAttribution: lhuria94 at Srijan | A Material+ Company commentedRemove preg_replace() & se as it is deprecated and suggested to preg_replace_callback().
Comment #10
lhuria94 CreditAttribution: lhuria94 at Srijan | A Material+ Company commentedComment #11
joachim CreditAttribution: joachim commentedThese don't need to be preg_replace_callback() -- AFAICT there is no executable code in the replacement.
Comment #12
lhuria94 CreditAttribution: lhuria94 at Srijan | A Material+ Company commentedUpdated patch. Ignore previous one please.
Comment #13
lhuria94 CreditAttribution: lhuria94 at Srijan | A Material+ Company commentedComment #14
somersoft CreditAttribution: somersoft commentedComment #15
longwaveClosed the following as duplicates:
#2843864: Examples in filter.api.php use deprecated regular expression modifier "e"
#2943290: filter.api.php is insecure and does not pass php7 tests
#3006195: Error with PHP7
Comment #16
longwaveSuggested patch looks fine to me, I agree with #11, and ultimately it doesn't really matter as this is just sample code in documentation, it's not really used for anything.
Comment #17
John Morahan CreditAttribution: John Morahan as a volunteer commented#12 doesn't look right to me...
\s*<br />
as a modifier? And I get a warning if I try to run it:preg_replace(): Unknown modifier '\'
Comment #18
sjerdoPatch #5 looks good to me.
Rebased patch #5.
Comment #19
dan2k3k4 CreditAttribution: dan2k3k4 at Amazee Labs commentedLooks good to me.
Comment #20
ravikk-drupal CreditAttribution: ravikk-drupal at TATA Consultancy Services for Pfizer, Inc. commentedComment #21
ravikk-drupal CreditAttribution: ravikk-drupal at TATA Consultancy Services for Pfizer, Inc. commentedThis patch perfectly works for me. Screenshot attached for the same.
Comment #22
joseph.olstadComment #23
apadernoComment #24
mcdruidLGTM
Comment #25
Liam MorlandComment #26
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedApproved, RTBM.
Let's get this in!
Comment #27
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedComment #29
mcdruidThank you!