Announcement

Collapse
No announcement yet.

Help with PHP - Glossary

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jago
    replied
    Any good coders here that can produce a hack to complete this work? Basically I would like to replace certain words with links.

    Here is something similar from vbulletin.org. Any help is greatly appreciated.

    http://www.vbulletin.org/forum/showt...ghlight=amazon

    Leave a comment:


  • txn.cracky
    replied
    Ok I removed addslashes and the quotes..

    Ok.. here are the fields in the table:
    Code:
     g_id     g_word     g_replacement
      1      bob      Bob
      2      txn      TXN
      3     teamxenon.net   <a href="http://www.teamxenon.net">teamxenon.net</a>
      4     AGN   <a href="http://www.ausgamers.com">AusGamers</a>

    And this is what happens when I actually type a proper link to teamxenon.net:
    Code:
    <a target='_blank' href="http://www.<a href="http://www.teamxenon.net">teamxenon.net</a>"><a href="http://www.teamxenon.net">teamxenon.net</a></a>
    Another thing could be contributing to this problem, is that I got an automatic URL parser, which looks like this:
    PHP Code:
      $input preg_replace("#([\n ])([a-z]+?)://([^\t <\n\r]+)#i""\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>"$input); 
    But the variable is first parsed through the url parser, before the glossary..


    By the way, I changed the do_glossary function a bit beacause it was throwing up errors.. here's the new one:
    PHP Code:
    function do_glossary($input) {
     
    $strsql "SELECT * FROM glossary";
     
    $result mysql_query($strsql);
     
    $max mysql_num_rows($result);
     for (
    $i=0$i <= $max$i++) {
      
    $row mysql_fetch_row ($result);
      
    $orig $row[1];
      
    $repl $row[2];
      
    $input str_replace($orig$repl$input);
     }
     return(
    $input);

    Last edited by txn.cracky; Tue 25 Jun '02, 12:27am.

    Leave a comment:


  • Raz Meister
    replied
    Can you post the contents of the table?

    Also try removing the addslashes as I don't think its necassary.
    And remove the quotes from the str_replace.

    Leave a comment:


  • txn.cracky
    started a topic Help with PHP - Glossary

    Help with PHP - Glossary

    Hello,

    I need some help with a glossary I'm trying to make, any help is greately appreciated. Note that this has nothing to do with vB.

    Ok, this is the deal.. When someone posts a comment or a news artice, the variable is passed through a function called do_glossary. What the function is supposed to do is replace words with other words. For exaple, so the user would not have to specify a link all the time to a certain page, the glossary should do that for him/her.

    The table "glossary" cosists of g_id (which is the ID, for easier management), g_word (word to be replaced), and g_replacement.

    The code of the function is:
    PHP Code:
    function do_glossary($input) {
     
    $strsql "SELECT * FROM glossary";
     
    $result mysql_query($strsql);
     
    $max mysql_num_rows($result);
     for (
    $i=0;$i <= $max;$i++) {
      
    $orig addslashes(mysql_result($result"""g_word"));
      
    $repl addslashes(mysql_result($result"""g_replacement"));
      
    $input str_replace("$orig""$repl"$input);
     }
     return(
    $input);

    The code above works perfectly for simple words. Such as replacing "bob" with "Bob". The problem comes in when I want to replace words with links. For example changing:
    Code:
    Bob's page
    into
    <a href="http://www.bob.com/bob">Bob's Page</a>
    Now, the problem, what if someone already put the link to Bob's page.. the above function would turn it into something like:
    Code:
    <a href="http://www.bob.com/bob"><a href="http://www.bob.com/bob">Bob's Page</a></a>
    Is there any way around this?
    Thanks
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X