ipwnzphp Posted April 25, 2009 Share Posted April 25, 2009 The code below just keeps displaying the content over and over. It links the auto keywords. But not in every repeat of the content. Also when i add a keyword phrase to the database it will remove the keyword form the other pages and show the new keyword i entered in only. Need it so i can have multiple keywords on every page. I thought this would work. But i must need to array something. Any help is much appreciated. <? $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $recipe->ingredients); print $theviddetails2; } ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/ Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 Anyone? still trying to get this. nothing i am trying is working. Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819250 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 Use this code instead and let us know if it fixes the problem (removed the "echo" command from within the loop, it will now echo the fully formatted text only after it's finished formatting). <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $recipe->ingredients); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819253 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 Shows content once now. But does not link the keywords now. Use this code instead and let us know if it fixes the problem (removed the "echo" command from within the loop, it will now echo the fully formatted text only after it's finished formatting). <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $recipe->ingredients); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819258 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 Sorry, it was my bad, there's more work to be done and while I kinda knew that, it wasn't exactly clicking. This should properly format the text for you: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); $theviddetails2 = $reciple->ingredients; while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819260 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 Dose not show the content at all now. Sorry, it was my bad, there's more work to be done and while I kinda knew that, it wasn't exactly clicking. This should properly format the text for you: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); $theviddetails2 = $reciple->ingredients; while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819264 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 Bah, I feel like an amateur. Just a spelling error, sorry: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); $theviddetails2 = $recipe->ingredients; while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819266 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 Nope, Still does not show the content at all. Bah, I feel like an amateur. Just a spelling error, sorry: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); $theviddetails2 = $recipe->ingredients; while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819267 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 Welp, it's not a spelling error now. Try running this for me: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); echo (empty($recipe->ingredients)) ? 'Ingredients is empty ' : ''; $theviddetails2 = $recipe->ingredients; echo (empty($theviddetails2)) ? 'Vid Details is empty ' : ''; while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; echo (empty($theviddetails2)) ? 'Vid2 Details is empty ' : ''; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } echo (empty($theviddetails2)) ? 'Vid3 Details is empty ' : ''; print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819270 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 Returned Vid2 Details is empty Vid2 Details is empty Vid2 Details is empty Vid2 Details is empty Vid2 Details is empty Vid2 Details is empty Vid2 Details is empty Vid2 Details is empty Vid2 Details is empty Vid2 Details is empty Vid2 Details is empty Vid3 Details is empty Welp, it's not a spelling error now. Try running this for me: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); echo (empty($recipe->ingredients)) ? 'Ingredients is empty ' : ''; $theviddetails2 = $recipe->ingredients; echo (empty($theviddetails2)) ? 'Vid Details is empty ' : ''; while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; echo (empty($theviddetails2)) ? 'Vid2 Details is empty ' : ''; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } echo (empty($theviddetails2)) ? 'Vid3 Details is empty ' : ''; print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819271 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 There's a scope issue between "$theviddetails2 = $recipe->ingredients;" and "$theviddetails2 = preg_replace(...". Without knowing the exact context of the script, it'll be difficult to fix that issue for you. The most direct solution would be to declare $theviddetails2 outside the scope of any functions/classes. Then, within any functions/objects you want to use it, you'll have to declare it as a global variable using: global $theviddetails2; Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819273 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 umm say wat? lol. would it help if i showed u the link with my code? There's a scope issue between "$theviddetails2 = $recipe->ingredients;" and "$theviddetails2 = preg_replace(...". Without knowing the exact context of the script, it'll be difficult to fix that issue for you. The most direct solution would be to declare $theviddetails2 outside the scope of any functions/classes. Then, within any functions/objects you want to use it, you'll have to declare it as a global variable using: global $theviddetails2; Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819276 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 This is PHP's manual entry for variable scope, if this doesn't help I can try to help you further: http://us.php.net/global Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819280 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 i know what global is, i just dont understand what you are saying to do. This is PHP's manual entry for variable scope, if this doesn't help I can try to help you further: http://us.php.net/global Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819283 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 What about if i did $mn = split("\n", $recipe->ingredients); print_r($mn); to put the content in a array, Now how would i search and link? Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819284 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 The problem is that, where ever you're doing this: "$theviddetails2 = $recipe->ingredients;" $theviddetails2 becomes out of scope by the time you do this: "$theviddetails2 = preg_replace(..." inside of the loop. The only solution I can offer you is to define $theviddetails2 as a global variable whenever you use it inside a function or method (a class function). Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819285 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 Still no luck. <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); echo (empty($recipe->ingredients)) ? 'Ingredients is empty ' : ''; $theviddetails2 = $recipe->ingredients; echo (empty($theviddetails2)) ? 'Vid Details is empty ' : ''; while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; echo (empty($theviddetails2)) ? 'Vid2 Details is empty ' : ''; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } echo (empty($theviddetails2)) ? 'Vid3 Details is empty ' : ''; global $theviddetails2; print $theviddetails2; ?> The problem is that, where ever you're doing this: "$theviddetails2 = $recipe->ingredients;" $theviddetails2 becomes out of scope by the time you do this: "$theviddetails2 = preg_replace(..." inside of the loop. The only solution I can offer you is to define $theviddetails2 as a global variable whenever you use it inside a function or method (a class function). Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819290 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 Is this the exact context of your code? This is a copy+paste from what is actually running on your server? Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819292 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 I have attached the full file of the code. Is this the exact context of your code? This is a copy+paste from what is actually running on your server? [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819293 Share on other sites More sharing options...
Solar Posted April 25, 2009 Share Posted April 25, 2009 Since this is an echo, doesn't your code need slashes? <?php echo (empty($theviddetails2)) ? 'Vid2 Details is empty ' : ''; $theviddetails2 = preg_replace\("$keyword", "<a href=\'$link\' target=\'$target\' style=\'text-decoration:none; border-bottom: 1px dotted;\'>$keyword</a>", $theviddetails2); } ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819295 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 if you used " " not ' ' Since this is an echo, doesn't your code need slashes? <?php echo (empty($theviddetails2)) ? 'Vid2 Details is empty ' : ''; $theviddetails2 = preg_replace\("$keyword", "<a href=\'$link\' target=\'$target\' style=\'text-decoration:none; border-bottom: 1px dotted;\'>$keyword</a>", $theviddetails2); } ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819297 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 Solar, no. The slashes will break it. Using single quotes inside double quotes (or visa versa, double quotes inside single) will cause the single (or double) quote to be printed normally. ipwnzphp, I really don't know what to tell you. The code appears to lose scope on the variable without any particular reason. While the loop does create a new block context, I've never used a PHP parser that caused scope issues except when changing functions or classes. You can try this, it's a lot of unnecessary processing, but maybe it'll work: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); $some_flag = FALSE; while ($url = mysql_fetch_array($pull_url)) { if (!$some_flag) { $theviddetails2 = $recipe->ingredients; $some_flag = TRUE; } $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819299 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 nope did not work. well crap! Solar, no. The slashes will break it. Using single quotes inside double quotes (or visa versa, double quotes inside single) will cause the single (or double) quote to be printed normally. ipwnzphp, I really don't know what to tell you. The code appears to lose scope on the variable without any particular reason. While the loop does create a new block context, I've never used a PHP parser that caused scope issues except when changing functions or classes. You can try this, it's a lot of unnecessary processing, but maybe it'll work: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); $some_flag = FALSE; while ($url = mysql_fetch_array($pull_url)) { if (!$some_flag) { $theviddetails2 = $recipe->ingredients; $some_flag = TRUE; } $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819300 Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 ipwnzphp, try one more thing for me: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); $theviddetails2 = $recipe->ingredients; while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; echo strlen($theviddetails2).' '; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819301 Share on other sites More sharing options...
ipwnzphp Posted April 25, 2009 Author Share Posted April 25, 2009 shows this: 12011201120112011201135613561356135613561523152315231523152315231523152315231523152315231523152315231523152315231523152315231523152315231523152315231523152315231523152315231523152315231523152315231523152315231685201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015201520152015217121712171217123282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328232823282328242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242724272427242700000000000 ipwnzphp, try one more thing for me: <?php $pull_url = mysql_query("SELECT * FROM `jos_autolinks`"); $theviddetails2 = $recipe->ingredients; while ($url = mysql_fetch_array($pull_url)) { $keyword = $url['phrase']; $link = $url['link']; $target = $url['target']; echo strlen($theviddetails2).' '; $theviddetails2 = preg_replace("/$keyword/", "<a href='$link' target='$target' style='text-decoration:none; border-bottom: 1px dotted;'>$keyword</a>", $theviddetails2); } print $theviddetails2; ?> Link to comment https://forums.phpfreaks.com/topic/155651-keyword-autolinks-help/#findComment-819304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.