Linking to a certain word on a page

Discussion in 'PHP' started by ojsimon, Nov 19, 2007.

  1. #1
    Hi
    I was wondering if it is possible to make a link so that it takes you staight to a cerain word on a page which, would be a variable in my code.
    Thanks
     
    ojsimon, Nov 19, 2007 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you would have to enclose each word in a div tag, like ( i think):
    <div id="word">word</div>

    and then link to page.php#word
     
    matthewrobertbell, Nov 19, 2007 IP
  3. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #3
    Suppose you want to make anchor for word Google in the middle of page. Place this html after the word Google <A name=google></A> than in your link for Google use this HTML <A href="#google">Shipping/Delivery</A>
     
    greatlogix, Nov 19, 2007 IP
  4. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    I was searching for the same thing. I managed to find it on a forum side.

    
    
    <? 
    $file = 'key.txt'; 
    $newfile = 'key.txt.bak'; 
    
    if (!copy($file, $newfile)) { 
        echo "failed to copy $file...\n"; 
    } 
     $ac=fopen("key.txt","r"); 
    while(!feof($ac)) 
    { 
    $al=fgets($ac, 1024); 
    $url1= $al; 
    $url= makeSEO($al); 
    $parcala=explode(" ",$url); 
    if(count($al) < 2) { 
    $adi=$parcala[0]; 
    } else {  
    $sayim= count($url); 
    for($i=2; $i <= $sayim;$i++) { 
    } 
    } 
    
    if($adi) 
    { 
    //echo $url.'<br>'; 
    echo '<a href="'.$url.'.htm">'.$url1.'</a><br>'; 
    } 
    else 
    { 
    echo 'Eklemeyedim Sorun Oluþtu'; 
    } 
    } 
    ?>  
    
     <?php 
    
    function makeSEO($text) { 
        $text=str_replace(" ","-",trim($text)); 
        $text=preg_replace("@[^A-Za-z0-9\-_ÐÜÞÝÖÇðüþýöç]+@i","",$text); 
        $text=ereg_replace(" +"," ",trim($text)); 
        $text=ereg_replace("[-]+","-",$text); 
        $text=ereg_replace("[_]+","_",$text); 
        $text=strtolowerTR($text); 
        if ((substr($text,-1)=='_')||(substr($text,-1)=='-')) $text=substr($text,0,-1); 
        return $text; 
    } 
    
    function strtolowerTR($text) { 
        $TRBul=array('Ð','Ü','Þ','Ý','Ö','Ç','ð','ü','þ','ý','ö','ç'); 
        $TRDegistir=array('g','u','s','i','o','c','g','u','s','i','o','c'); 
        $text=str_replace($TRBul,$TRDegistir,$text); 
        $text=strtolower($text); 
        return $text; 
    } 
    
    ?> 
    
    
    
    
    PHP:


    key.txt must be chmod 777.

    I did not try it my self yet.
     
    baris22, Nov 19, 2007 IP