Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Jak aktywować linki?
julss
post
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 17.10.2006

Ostrzeżenie: (0%)
-----


Jestem w 'Przedszkolu' bo niestety nie znam się na programowaniu.
Mam gotowy kod strony.
Newsy są wgrywane na stronę przez Panel Admin (własna kreacja programisty).

Niestety w wyświetlanych Newsach linki nie są aktywne (IMG:style_emoticons/default/thumbsdownsmileyanim.gif)
Jak zmienić kod by były??

Wklejam fragment kodu:

Kod
<?php

        ob_start();
        
        include_once '../include/headers.php';
        include_once '../include/classes/mysql.class.php';
        include_once '../include/functions_de.php';
        
        print file_get_contents('../include/html/header.html');
        
        ?>

<?php
                        
                                $operation = new OperationsMySQL();
                                $operation->connect();
                                
                                if(!isset($_GET['id']))
                                
                                {
echo '<div class="small_news">';                
                $query = "SELECT id, regdate, title, info_small FROM newsesde WHERE visible = '1' AND (regdate >= '" . date('Y-m-d') . "'
OR regdate <= regdate_end AND regdate_end >= '" . date('Y-m-d') . "')  ORDER BY regdate ASC LIMIT 9";
                $operation->execute_query($query);
    
               while($row = $operation->fetch_object())                
                {
                print '<div class="top_news">' . "\n";
                        if(file_exists('../admin-news-de/news-images/' . $row->id . '.jpg'))
                        {
                        
                        print '
<div class="imgs" >
    <table height="161" align="center" width="100%">
        <tr>
            <td align="center" valign="middle" class="img_block"><img src="../admin-news-de/news-images/' . $row->id . '.jpg" alt="" /></td>
        </tr>
    </table>
</div>';
                        
                        }
                        
                        print '
                        <p class="news_date" style="margin-bottom: 10px; width: 250px;">
                        ' . date('d.m.Y', strtotime($row->regdate)) . '</p>' . "\n";
                        print '                                                
                        <p class="title_top">';
                      echo '  <a href="?id=' . $row->id . '">' . $row->title . '</a></p>';
                        
                        
                        print '                                        
                        </div>' . "\n";
                        
                        $last_date = $row -> regdate;
                }
                
             $operation->free_result();
    echo '</div>';
    
    if($last_date < date('Y-m-d')){$last_date = date('Y-m-d');}
    
                                                echo $output;
                                                print '                                        <hr id="news_line" />' . "\n";
                                                $query2 = "SELECT id, regdate, title, info_small FROM newsesde WHERE visible = '1'
AND (regdate >= '" . date('Y-m-d') . "' OR regdate <= regdate_end AND regdate_end >= '" . date('Y-m-d') . "')  ORDER BY regdate ASC LIMIT 9";
                                                $operation->execute_query($query2);
                                                
                                                print '<p style="clear: both;"></p>';
                                                print '                                        <ul class="ul_no_list ">' . "\n";
                                                $output="";
                                                $news = 0;
                                                while($row = $operation->fetch_array())
                                                {
                                                    if($news > 9){
                                                    extract($row);
                                                        $output .= '                                                        <li class="regdate">' . date('d.m.Y', strtotime($regdate)) . '</li>                                                        
<li class="title"><a href="?id=' . $id . '">' . $title . '</a></li>                                                        <li class="info_small">' . $info_small . '</li>';
                                                    }
                                                    $news++;
                                                }
                                                echo $output;
                                                print '                                                </ul>' . "\n";
                                                }
                                        else
                                        {
                                        $query = sprintf("SELECT id, regdate, title, info_small, info FROM newsesde WHERE id = '%d' AND visible = '1' LIMIT 1", mysql_real_escape_string($_GET['id']));
                                                $operation->execute_query($query);
                                                $row = $operation->fetch_object();
                                                
                                                print '<p id="news_date_p"><span class="news_date">' . date('d.m.Y', strtotime($row->regdate)) . '</span></p>' . "\n";
                                                print '                                        <p class="text_link">' . $row->title . '</p>' . "\n";
                                                print '                                        <p class="text_normal">' . nl2br($row->info) . '</p>';
                                                print '                                        <p class="back"><a href="index.php">&lt;&lt; zurück</a></p>' . "\n";
                                        }
                        
                                        ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
markonix
post
Post #2





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

Ostrzeżenie: (0%)
-----


  1. function clickableLinks($source) {
  2.  
  3. $m = preg_match_all('/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/', $source, $match);
  4.  
  5. if ($m) {
  6. $links = $match[0];
  7. for ($j = 0; $j < $m; $j++) {
  8. if (preg_match('/http:\/\/JAKAS.STRONA.PL/i', $links[$j])) {
  9. $title = 'Link do podstrony';
  10. } else {
  11. $title = 'Link zewnętrzny!';
  12. }
  13. $source = str_replace($links[$j], '<a href="'. $links[$j] .'" title="'. $title .'">'. $links[$j] .'</a>', $source);
  14. }
  15. }
  16.  
  17. return $source;
  18.  
  19. }


JAKAS.STRONA.PL zamień na swój adres. Funkcja oprócz tego, że zamienia tekst na linki to dodatkowo do nich dokleja tytuł "link do podstrony" bądź "link zewnętrzny".
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 04:00