I want to replace this:

d+

with the node teaser

where d+ is the node id

I use php:
<%php

foreach ($matches as $vars){
$node = node_load($vars);
}

$replace = $node->teaser;

return $replace;

%>

But it does not work why?

I will appreciate your help.

Comments

bassio’s picture

Sorry

<teaser>\d+</teaser>

arhip’s picture

First, you should escape all regex special characters by adding backslashes like this:

/\<teaser\>(\d+)\<\/teaser\>/i

Parentheses used to identify substrings matched. So if you want to extract that decimal number and eliminate the surrounding tag, that d+ should be parenthesized.

In the replacement code, you must not include <?php ... ?> tag. And instead of iterating through every matched string, we can use $matches[1] to get the first substring matches (that is the digit we want). The code could be like this:

if ($matches[1]) {
  $node = node_load($matches[1]);
  $replace = $node->teaser;

  return $replace;
}
else
  return "";

Hope it helps.

avpaderno’s picture

Status: Active » Fixed

I am setting the report as fixed because it got an answer.

Status: Fixed » Closed (fixed)

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