0

I have a hashtag script running that creates a link to another page on my social network. right now i have it set so that U = logged in user name and TAG = the hashtag being used. for some reason the variable $logged username isnt giving a result when the user is logged in or logged out. its just blank. below is the hashtag script i am running

<?php
///hashatg script
function convertHashtag($str){
    $regex = "/#+([a-zA-Z0-9_]+)/";
    $str = preg_replace($regex, '<a href="/hashtag.php?u='.$log_username.'&tag=#$1" title="all posts that include  #$1">$0</a>', $str);
    return($str);
}
$string = $statuslist;
$string = convertHashtag($string);
?>

below is the link that is produced, u should = logged user name, like: betty, frank, peter, etc.

http://website.com/hashtag.php?u=&tag=#myhashtag

should read

http://website.com/hashtag.php?u=betty&tag=#myhashtag
peter
  • 169
  • 1
  • 1
  • 9

1 Answers1

2

Try this:

<?php
///hashatg script
function convertHashtag($str){
    global $log_username;
    $regex = "/#+([a-zA-Z0-9_]+)/";
    $str = preg_replace($regex, '<a href="/hashtag.php?u='.$log_username.'&tag=#$1" title="all posts that include  #$1">$0</a>', $str);
    return($str);
}
$string = $statuslist;
$string = convertHashtag($string);
?>

Or the following, depending on how you want to define your parameters

<?php
///hashatg script
function convertHashtag($str, $log_username){
    $regex = "/#+([a-zA-Z0-9_]+)/";
    $str = preg_replace($regex, '<a href="/hashtag.php?u='.$log_username.'&tag=#$1" title="all posts that include  #$1">$0</a>', $str);
    return($str);
}
$string = $statuslist;
$string = convertHashtag($string, $log_username);
?>

You need to define your parameters inside or thru your functions.

SAVAFA
  • 818
  • 8
  • 23