Closed (fixed)
Project:
Custom filter
Version:
5.x-1.2
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
27 Dec 2007 at 16:01 UTC
Updated:
15 Jul 2009 at 14:50 UTC
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
Comment #1
bassio commentedSorry
<teaser>\d+</teaser>Comment #2
arhip commentedFirst, you should escape all regex special characters by adding backslashes like this:
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:Hope it helps.
Comment #3
avpadernoI am setting the report as fixed because it got an answer.