changing some php code into a function...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,
I wrote the following code to change some string into friendly URL, like 
in WP blogs and blogspot. Now I want to use it every for linking in all 
the pages. I thought of functions and tried to convert it into a 
function, but failed. How can I do this? or is there any other way to 
have URL links as it is in blogpost.
http://www.somesite.com/the-name-of-the-page-comes-here.html

here is the code:

    <?php
    $string = "Here's the name of the page";
    $string = strtolower($string);
    $rg = "[^a-zA-Z0-9]";
    $parts = preg_match_all("/$rg/", $string, $matches);
    $high = implode(" ", $matches[0]);
    $input = $high;
    $words = explode(" ",$input);
    foreach ($words as $term) {
        $string = str_replace($term,"",$string);
    }
    while(strpos($string, " ")) {
    $string = str_replace(" ", "-", $string); }
    echo "<a href=\"".$string.".html\">".$string.".html</a>";
    ?>



[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux