Problems getting field value into custom php (Undefined index & Undefined offset errors)

Events happening in the community are now at Drupal community events on www.drupal.org.
hampshire's picture

I am trying to use the following php to take the url from Field A, clean it up, and save it to Field B.

If I put the domain in manualy the rule works just fine and saves somedomain.com to Field B

<?php

$myurl
= get_domain ('http://store.somedomain.com/cart/index.php');

function
get_domain ($url) {
$raw_url= parse_url($url);
preg_match ("/.([^\/]+)/", $raw_url['host'], $domain_only);
return
strtolower($domain_only[1]);
}

echo
$myurl;

?>

If however I try to call the address using a token as shown next I get the errors at the bottom of this post and nothing gets saved to Field B. How am I supposed to get the value from field_url into the php so that this can work.

<?php

$myurl
= get_domain ('[node:field-url]');

function
get_domain ($url) {
$raw_url= parse_url($url);
preg_match ("/.([^\/]+)/", $raw_url['host'], $domain_only);
return
strtolower($domain_only[1]);
}

echo
$myurl;

?>

Errors

•Notice: Undefined index: host in get_domain() (line 7 of /rules/modules/php.eval.inc(125) : eval()'d code).
•Notice: Undefined offset: 1 in get_domain() (line 8 of /rules/modules/php.eval.inc(125) : eval()'d code).

Thanks

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: