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

joachim created an issue. See original summary.

joachim’s picture

Title: sample for for callback_filter_process() and callback_filter_prepare() should not include deprecated regex option » sample code for callback_filter_process() and callback_filter_prepare() should not include deprecated regex option
rashid_786’s picture

According to you it should be without 'e' option like the following line?

$text = preg_replace('|<code>(.+?)|s', "[codefilter_code]$1[/codefilter_code]", $text);

joachim’s picture

Yup, that looks fine. The 'e' option wasn't doing anything anyway, since the replacement parameter isn't executable code.

shashikant_chauhan’s picture

StatusFileSize
new1.05 KB

adding patch.

shashikant_chauhan’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: 2788565-5.patch, failed testing.

sutharsan’s picture

Issue tags: +Dublin2016
lhuria94’s picture

Remove preg_replace() & se as it is deprecated and suggested to preg_replace_callback().

lhuria94’s picture

Status: Needs work » Needs review
joachim’s picture

Status: Needs review » Needs work

These don't need to be preg_replace_callback() -- AFAICT there is no executable code in the replacement.

lhuria94’s picture

Updated patch. Ignore previous one please.

lhuria94’s picture

Status: Needs work » Needs review
somersoft’s picture

Related issues: +#3006195: Error with PHP7
longwave’s picture

Status: Needs review » Reviewed & tested by the community

Suggested 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.

john morahan’s picture

Status: Reviewed & tested by the community » Needs work

#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 '\'

sjerdo’s picture

Status: Needs work » Needs review
Issue tags: +PHP 7.0 (duplicate)
StatusFileSize
new1.05 KB

Patch #5 looks good to me.
Rebased patch #5.

dan2k3k4’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

ravikk-drupal’s picture

Assigned: Unassigned » ravikk-drupal
ravikk-drupal’s picture

StatusFileSize
new32.63 KB

This patch perfectly works for me. Screenshot attached for the same.

joseph.olstad’s picture

Issue tags: +PHP 7.4
avpaderno’s picture

Assigned: ravikk-drupal » Unassigned
mcdruid’s picture

Issue tags: +Pending Drupal 7 commit

LGTM

liam morland’s picture

fabianx’s picture

Approved, RTBM.

Let's get this in!

fabianx’s picture

Assigned: Unassigned » mcdruid

  • mcdruid committed 9ed3f67 on 7.x
    Issue #2788565 by lhuria94, shashikant_chauhan, sjerdo, ravikk-drupal,...
mcdruid’s picture

Assigned: mcdruid » Unassigned
Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.