Help - Search - Members - Calendar
Full Version: Comment Name Help
Codegrrl.com Forums > Script Help > Tutorial Help
Steven
I have been trying to fix this for a couple weeks now, but I can't get it to work.

What I want to happen is to check whether the commenter entered a URL. (After I run the stripslashes function the URL is "http:///"). If they did, display their name as a link. If not, don't display it as a link. Here is my latest code on my journal page:
CODE

<?php if (stripslashes($row['url']) == "http:///") { printf("%s", stripslashes($row['name'])); } else { printf("<a href=\"%s\">%s</a>", stripslashes($row['url']), stripslashes($row['name'])); } ?>
Amelie
Try

CODE
<?php
if (!empty($row['url']) && $row['url'] != 'http://') {
    printf('<a href="%s">%s</a>', $row['url'], stripslashes($row['name']);
}
else {
    echo stripslashes($row['name']);
} ?>


You don't need to run stripslashes on the URL since it will not contain any quotes. Quotes are the only things that are escaped with backslashes, and as the URL won't contain any, you don't need to use it. I have also switched printf to echo for the name field (when no URL is entered) as I find it more readable, however both will work.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.