frkmilla Posted February 18, 2010 Share Posted February 18, 2010 I am trying to get a script that makes my predefined keyword converted to links and / or converted to a certain color, size and so on... In one of the other threads Ive posted I got an answer I am a bit curious on, I'll just quote the answer, and hopefully some of you can help me with this.... see my answer below, and help If you want... I'll be forever grateful.... Quote from: Grayda on Today at 12:26:29 AM I think I get it. You want certain words to be, say, red. And you want other words to be made in to a link? I think this should help: Code: <?php$mytext = "Buffalo with an aqualung";$mytext = str_replace("Buffalo", "<a href='buffalo.php'>Buffalo</a>", $mytext);$mytext = str_replace("aqualung", "<b>aqualung</b>", $mytext);echo $mytext So when you run the script, Buffalo will be replaced with a link to buffalo.php and aqualung will be made bold. That, of course, is the simple way to do it. You can get complex with regexes and whatnot, but if you're only doing a few things at a time, this is ideal. bah.. Im still struggling with this... could anyone be helpful explaining to me how I can use this example in my site? I don't understand a thing, and probably shouldn't be messing with this kind of codes.. lol... :'( Before my text that needs to be converted I have three other pages included: <?php include "../url/url.php"; ?> <?php include "url.php"; ?> <?php include "url/url.php"; ?> These makes the top of my pages, and I was hoping that I could set the code in one of those so I don't have to copy&paste the script into every single page... Don't I need any more script than those few lines? Im desperate.... lol.... please help... Quote Link to comment Share on other sites More sharing options...
teamatomic Posted February 18, 2010 Share Posted February 18, 2010 I think this might be what you are asking. Put the function into a php file and include it. Then call them as shown. For the colors to use google "named colors". function color($value, $color) { $out="<span style=\"color:$color;\">$value</span>"; return $out; } function linker($linker) { $out = "<a href=\"./$linker\">$linker</a>"; return $out; } echo linker('test_link.php'); echo "<br>"; echo color('tester text', 'green'); Quote Link to comment Share on other sites More sharing options...
frkmilla Posted February 18, 2010 Author Share Posted February 18, 2010 I think this might be what you are asking. Put the function into a php file and include it. Then call them as shown. For the colors to use google "named colors". function color($value, $color) { $out="<span style=\"color:$color;\">$value</span>"; return $out; } function linker($linker) { $out = "<a href=\"./$linker\">$linker</a>"; return $out; } echo linker('test_link.php'); echo "<br>"; echo color('tester text', 'green'); So If I put this code into a php file (with adding <? php on the top and ;?> on the bottom, "php include" this file into my site, what here defines my keywords and colors and links and so on? Is this code totally different from the previous code I got? and yes, I still don't have a clue... lol :-\ Quote Link to comment Share on other sites More sharing options...
Hailwood Posted February 18, 2010 Share Posted February 18, 2010 I think this might be what you are asking. Put the function into a php file and include it. Then call them as shown. For the colors to use google "named colors". function color($value, $color) { $out="<span style=\"color:$color;\">$value</span>"; return $out; } function linker($linker) { $out = "<a href=\"./$linker\">$linker</a>"; return $out; } echo linker('test_link.php'); echo "<br>"; echo color('tester text', 'green'); So If I put this code into a php file (with adding <? php on the top and ;?> on the bottom, "php include" this file into my site, what here defines my keywords and colors and links and so on? Is this code totally different from the previous code I got? and yes, I still don't have a clue... lol :-\ seriously... you have been given all the help you should need. these will do the formatting for you however YOU must define what context they are used in. how are we meant to know what your text is coming from? is it a string? what? please show us your attempt... Quote Link to comment Share on other sites More sharing options...
teamatomic Posted February 18, 2010 Share Posted February 18, 2010 what here defines my keywords and colors and links and so on? You define your keywords/links and colors, its your script. $my_new_nightmare= linker($my_link_keyword); $my_aura= color($my_text_keyword,$my_color); Hit the PHP manual...functions>user defined functions. Then do a bit of experimenting. you know the old adage; give a man a fish...teach a man to fish Go fishing! its fun and very nutritious. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
frkmilla Posted February 18, 2010 Author Share Posted February 18, 2010 Sorry, It is not my intention to "demand" all the help, but since I don't know how to put this script into my site, I have to ask... how are we meant to know what your text is coming from? I see your point, but I don't know other ways to explain it than it is normal HTML within <table> tags on several pages. I have a fully function website with alot of information and would like to implement this script now after I am finished... But I understand I have to learn someting new before I ask more.. lol... thanks for all the help so far, I will try to make it work somehow... Quote Link to comment Share on other sites More sharing options...
Hailwood Posted February 19, 2010 Share Posted February 19, 2010 Well, are you manually entering the data on the page, or is the data being pulled from a database? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.