Re: php string within string compare

2010-06-01 11:58:51

Bill Hernandez

Previous | Next

I didn't get a chance to run this code, I just wrote it on the fly, but you can test it...

<?php
$br = "<br>";
$brn = "<br>\n";

function bh_process_url($needle, $haystack, $url_string, $html_page, $true_class, $false_class == "", $return_string = false)
{
$str = "";
if (stristr($haystack,$needle))
{
$str .= "<a href=\"" . $html_page . "\" class=\"" . $true_class . "\">" . $url_string . "</a>"
}
else
{
if($false_class == "")
{
$str .= "<a href=\"" . $html_page . ">" . $url_string . "</a>" // if the $false_class is empty
}
else
{
$str .= "<a href=\"" . $html_page . "\" class=\"" . $false_class . "\">" . $url_string . "</a>"
}
}
if ($return_string) return $str; } else {echo $str; }
}

$needle = "BillOfRights";
$haystack = getenv ("REQUEST_URI");
$url_string = "The Bill Of Rights";
$html_page = $needle . ".html";
$true_class = "current";
$false_class = "not_current";
$return_string = true;

// Call the function this way, where it returns a value
$link = bh_process_url($needle, $haystack, $url_string, $html_page, $true_class, $false_class, $return_string);
echo $link . $brn;

// call the function without its last two parameters (using the default values)
bh_process_url($needle, $haystack, $url_string, $html_page, $true_class);
echo $brn;

?>

Best regards,

Bill Hernandez
Plano, texas

--
You received this message because you are subscribed to the Google Groups "Web Authoring" group.
To post to this group, send email to web-authoring@[Protected]
To unsubscribe from this group, send email to web-authoring+unsubscribe@[Protected]
For more options, visit this group at http://groups.google.com/group/web-authoring?hl=en.