Posted by hampshire on January 14, 2012 at 3:24pm
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