note 97013 deleted from language.operators.comparison by danbrown
| From: | danbrown@php.net | Date: | Mon, 29 Mar 2010 00:32:46 +0000 |
| Subject: | note 97013 deleted from language.operators.comparison by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167472@lists.php.net to get a copy of this message | ||
Note Submitter: Adam Thomas
----
A good use of the ternary if is to quickly format a user entered URL correctly with http:// if it is not detected. This ensures consistency.
<?php
$formatted_url = htmlspecialchars(((!strpos($_POST['link'],"://") &&
$_POST['link'] != NULL) ? "http://".$_POST['link'] :
$_POST['link']))
?>