Jump to content

Keyword Autolinks - HELP!


ipwnzphp

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.