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

  • Home
  • SEARCH
  • 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 1104559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:30:05+00:00 2026-05-17T01:30:05+00:00

I have developed a wordpress plugin that looks through a bunch of html and

  • 0

I have developed a wordpress plugin that looks through a bunch of html and detects any email address, replacing them by a non harvestable html markup (to be rerendered as an email via javascript for better usability).

So for instance, the function receives:

$content = "Hello john@doe.com. How are you today?";

and outputs:

$content = "Hello <span class="email">john(replace this parenthesis by @)example.com</span>. How are you today?";

My function works fine, but i would like now, to give an option to specify what the readable email should be like. So if the function receives:

$content = "Hello john@doe.com(John Doe). How are you today?";

the new output would be:

$content = "Hello <span class="email" title="John Doe">john(replace this parenthesis by @)example.com</span>. How are you today?";

So the regex should look for attached parenthesis, and if found, take what’s inside and add a html title attribute, remove the parenthesis, and then parse the email.

I’m pretty much clueless as to how to make it happen, because of the optional nature of the feature (meaning: those parenthesis won’t always be there).

Any pointer would be helpful, here is my current code:

function pep_replace_excerpt($content) {
     $addr_pattern = '/([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\.([A-Z]{2,4})/i';
        preg_match_all($addr_pattern, $content, $addresses);
        $the_addrs = $addresses[0];
        for ($a = 0; $a < count($the_addrs); $a++) {
            $repaddr[$a] = preg_replace($addr_pattern, '<span class="email" title="$4">$1(replace this parenthesis by @)$2.$3</span>', $the_addrs[$a]);
        }
        $cc = str_replace($the_addrs, $repaddr, $content);
        return $cc;
}
  • 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-17T01:30:05+00:00Added an answer on May 17, 2026 at 1:30 am

    Easy option might be checking with strpos for presence of parenthesis just after e-mail and then using regex to find first occurrence of ((.+?)) after the e-mail.

    The other option is to add ((.+?))? to your regex, the last question mark will make the group optional.

    Then the fool code will look like:

    function pep_replace_excerpt($content) {
         $addr_pattern = '/([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\.([A-Z]{2,4})(\((.+?)\))?/i';
            preg_match_all($addr_pattern, $content, $addresses);
            $the_addrs = $addresses[0];
            for ($a = 0; $a < count($the_addrs); $a++) {
                if(count($the_addrs[$i]) == 4)
                    $repaddr[$a] = preg_replace($addr_pattern, '$1(replace this parenthesis by @)$2.$3', $the_addrs[$a]);
                else
                    $repaddr[$a] = preg_replace($addr_pattern, '$1(replace this parenthesis by @)$2.$3', $the_addrs[$a]);
            }
            $cc = str_replace($the_addrs, $repaddr, $content);
            return $cc;
    }
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom developed WordPress plugin that is using jQuery 1.4 and for
I developed a plugin with Settings link that was working fine in WordPress 2.7.
I have developed a VB.NET WCF service that recives and sends back data. When
We have developed a website that uses MVC, C#, and jQuery. In one of
We have developed a webservice that sits and runs in the context of a
I have developed a framework that is used by several teams in our organisation.
I developed a wordpress plugin entirely on localhost and tested it on a live
I have developed a wordpress theme with header, footer, sidebar, index, page, single and
I develop a website with CMS WordPress. I don't have any errors on my
I have developed some software(vb.net) that records fees paid by the students. The purpose

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.