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 8009181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:22:08+00:00 2026-06-04T18:22:08+00:00

Symfony1 had a helper function called auto_link_text() , which parsed a block of text

  • 0

Symfony1 had a helper function called auto_link_text(), which parsed a block of text and wrapped all text URLs in <a> tags, automatically populating the href attribute.

Does Twig include a function like this? I’ve looked on Google, and gone through the code, but can’t find one. I can obviously code one myself, but don’t want to replicate something if it’s already there.

If I do code one myself, should it be a function or a filter?

  • 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-06-04T18:22:10+00:00Added an answer on June 4, 2026 at 6:22 pm

    the function doesn’t exist in twig, but you can even add your own extensions to Twig :

    class AutoLinkTwigExtension extends \Twig_Extension
    {
    
        public function getFilters()
        {
            return array('auto_link_text' => new \Twig_Filter_Method($this, 'auto_link_text', array('is_safe' => array('html'))),
            );
        }
    
        public function getName()
        {
            return "auto_link_twig_extension";
        }
    
        static public function auto_link_text($string)
        {
    
            $regexp = "/(<a.*?>)?(https?)?(:\/\/)?(\w+\.)?(\w+)\.(\w+)(<\/a.*?>)?/i";
            $anchorMarkup = "<a href=\"%s://%s\" target=\"_blank\" >%s</a>";
    
            preg_match_all($regexp, $string, $matches, \PREG_SET_ORDER);
    
            foreach ($matches as $match) {
                if (empty($match[1]) && empty($match[7])) {
                    $http = $match[2]?$match[2]:'http';
                    $replace = sprintf($anchorMarkup, $http, $match[0], $match[0]);
                    $string = str_replace($match[0], $replace, $string);
                }
            }
    
            return $string;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Symfony 1.4 and Doctrine. So far I had no problem running tasks
i am develping a project using symfony1.4.16 and Doctrine and for authentication i am
I have a problem with all my forms in symfony 1.4. They work with
I'm developing on Symfony2 in PHP and I'd like to find all my translation
I read the other PHPUnit installation questions but haven't had any success. What is
I am trying to display all categories (from my table Category) with radio buttons.
I am new to CI. Before I had worked extensively in RoR and Symfony.
I'm looking for a simpler test framework. I had a look at a few
My symfony project has an object A which has a one-to-many relationship with object(s)
I had a problem with symfony2 session component. I set some data to session

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.