User login

url

How to fetch a file at a URL and set it as the default image in an image field

There's two separate cool things here that you might want to do. One, simply know how to save a file from a URL (there's a secret Drupal function for that in system module) and two, how to give an image field a default image when creating it programmatically (that part is outsourced to the fieldhelp module).

Checking if a web site URL is valid: There's a Drupal function for that

drupal php check valid url

A too-simple snippet contributed elsewhere:

<?php
function valid_url($str)
{
    return ( ! preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $str)) ? FALSE : TRUE;
}
?>

After following this epic thread
http://drupal.org/node/124492
it becomes clear that Drupal has a wonderful valid_url function of its own, thanks to mfer

Syndicate content