Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6954217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:34:38+00:00 2026-05-27T14:34:38+00:00

My php function is returning an Error. these two function from the same class

  • 0

My php function is returning an Error.

these two function from the same class

error
Fatal error: Using $this when not in object context in D:\xampp\htdocs\admin\functions.php(98) : runtime-created function on line 1

public function noFollowLinks($str) {
    // replaces every link with the version provided by fixLink()
    return preg_replace_callback("#(<a.*?>)#i", create_function('$matches', 'return $this->fixLink($matches[1]);'), $str);
}

public function fixLink($input) {
    $whitelist = $GLOBALS['whitelist'];
    // if the link in $input already contains ref=”nofollow”, return it as it is
    if (preg_match('#rel\s*?=\s*?[\'"]?.*?nofollow.*?[\'"]?#i', $input)) {
        return $input;
    }
    // extract the URL from $input
    preg_match('#href\s*?=\s*?[\'"]?([^\'"]*)[\'"]?#i', $input, $captures);
    // $href will contain the extracted URL, such as http://seophp.example.com
    $href = $captures[1];
    // if URL doesn’t contain http://, assume it’s a local link
    if (!preg_match('#^\s*http://#', $href)) {
        return $input;
    }
    // extract the host name of the URL, such as seophp.example.com
    $parsed = parse_url($href);
    $host = $parsed['host'];
    // if the URL is in the whitelist, send $input back as it is
    if (in_array($host, $whitelist)) {
        return $input;
    }
    // assuming the URL already has a rel attribute, change its value to nofollow
    $x = preg_replace('#(rel\s*=\s*([\'"]?))((?(3)[^\'"]*|[^\'"]*))([\'"]?)#i', '\\1\\3,nofollow\\4', $input);
    // if the string has been modified, it means it already had a rel attribute,
    // whose value has been changed to nofollow, so we return the new version
    if ($x != $input) {
        return $x;
    }
    // if the link in the input string doesn’t have ref attribute, we add it
    else {
        return preg_replace('#<a#i', '<a rel="nofollow"', $input);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:34:39+00:00Added an answer on May 27, 2026 at 2:34 pm

    As Andrey said, you cannot use $this in the function created by create_function.
    My soultion to this, would be to replace your noFollowLinks with this:

    public function noFollowLinks($str) {
        // replaces every link with the version provided by fixLink()
        return preg_replace_callback("#(<a.*?>)#i", array($this, 'fixLinkCallback'), $str);
    }
    
    private function fixLinkCallback($matches) {
        return $this->fixLink($matches[1]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some issues returning data from on page, using jQuery, PHP and
I'm using the PHP function imagettftext() to convert text into a GIF image. The
I have a PHP function that takes a variable number of arguments (using func_num_args()
I'm trying to access an FTP server from my PHP script using Codeigniter's FTP
I'm using SQLite3, and the SQLite3 class that's built into PHP. The following code
I am returning results from a MySql database in PHP that I would like
I'll be the first to admit that PHP is not my forte and this
I'm using PHPMailer and $mail->Send() is returning an error, my problem is when I
I have a PHP function that returns an array. This is the output of
This query is not returning any result as there seems to be an issue

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.