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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:35:00+00:00 2026-06-18T21:35:00+00:00

I plan to use my custom function below while getting from data from my

  • 0

I plan to use my custom function below while getting from data from my mysql table & print it as html. Since htmlspecialchars() translate tags to html entities, I retranslate them ( p, br, strong) to tags.

My question is: Is it efficient enough or Is there any other shorter or more efficient way to achieve this aim? If you know any, can you please guide me with at least keywords? I can look fort he details in php.net and this site.

Thanks, regards

    function safe_output_from_mysql($safe_echo_to_html)
{
    $safe_echo_to_html = mb_convert_encoding($safe_echo_to_html, 'UTF-8', mb_detect_encoding($safe_echo_to_html));
    $safe_safe_echo_to_html = htmlspecialchars($safe_echo_to_html, ENT_QUOTES, "UTF-8");
    $safe_echo_to_html = preg_replace("&lt;br /&gt;","<br />",$safe_echo_to_html);
    $safe_echo_to_html = preg_replace("&lt;p&gt;","<p>",$safe_echo_to_html);
    $safe_echo_to_html = preg_replace("&lt;/p&gt;","</p>",$safe_echo_to_html);
    $safe_echo_to_html = preg_replace("&lt;strong&gt;","<strong>",$safe_echo_to_html);
    $safe_echo_to_html = preg_replace("&lt;/strong&gt;","</strong>",$safe_echo_to_html);
    return $safe_echo_to_html;
}
  • 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-18T21:35:01+00:00Added an answer on June 18, 2026 at 9:35 pm

    There is no need to call preg_replace() multiple times. You can use a single pattern to match all the desired tags:

    preg_replace('/&lt;\s*(\/?(?:strong|p|br)\s*\/?)&gt;/i', '<\1>', $s);
    

    I’m assuming, of course, that you’re actually planning to use regex to do the match. If the search strings are straight text, then strtr() is more efficient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I plan use HTML, ebook designer( HTML page builder) -> embed in iPad ->
we plan to use TIBCO EMS queues and TIBCO BW listeners on those queues
If I do a query (I plan to use SDS.P) against the global catalog,
Need an async I/O Processing Plan to use async I/O through aio* calls on
I am developing a web app for which I plan to use InnoDB. However
I'm looking for a a mouseover sound script (for button). I plan to use
I'm working on a document storage. Therefore I plan to use SqlServer 2012 with
I am using mod_perl for my web application. Currently, I plan to use a
We use scrum technique to plan for short development lifecycle. It is very common
I use Visual Studio .NET to develop a component named X_Component and I plan

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.