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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:15:28+00:00 2026-05-30T20:15:28+00:00

I have some code I that although it works, its making my content erratic.

  • 0

I have some code I that although it works, its making my content erratic. Let me explain.

I created a text chatting app for studying PHP etc and, long story short, the user types a message, the message gets logged in db and prints it back out onto the page on certain fields (below)

this is how the page gets its content (in short so I don’t fill the page with code)

while($row = mysqli_fetch_array($dbqDoIt4_mssgs)){
            $i++;

             //====== TURN REGULAR LINKS TO CLICKY LINKS USING REGEXP.

$URL = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
$text = $row['mssg'];
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {

       // make the urls hyper links
       echo preg_replace($reg_exUrl, "<a href='{$url[0]}'>{$url[0]}</a> ", $text);

}

//======= 


            echo '<div class="holdChat">
                        <span class="orangeBigger">' . strtoupper($row['user']). '</span>' . ' ' . '<span class="txtSaid">said:</span> ' . '<span style="color:#171717;">' . $text . '</span>' . '</div>' . 
            '<div class="chatTimeBox">' . $row['time'] . '</div><br/>';

                if($i == 20){
                    break;  
                }
            }

Essentially,this gets all the content upto 20 and breaks etc…

So with the above in ONE line, you get USER-NAME SAID: " --message here -- which
appears in a grey-ish div.

now, the problem i was having was, getting links to show as links when the echo is made to the page.

this is the code i went with (with help from others)

//====== TURN REGULAR LINKS TO CLICKY LINKS USING REGEXP.

$URL = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
$text = $row['mssg'];
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {

       // make the urls hyper links
       echo preg_replace($reg_exUrl, "<a href='{$url[0]}'>{$url[0]}</a> ", $text);

}

//======= 

The problem I’m currently having is that when a link is written in the post, it repeats the content written…or rather, it appears twice on the page. if the post doesn’t have any links, it appears as it should.

so for example, without a link in the text it appears like this USER-NAME SAID: " --message here --

with any links on the text, I get a double post one on top of the other like this

USER-NAME SAID: " --message here --

USER-NAME SAID: " --message here --

which throws it all off.

I’m at my wits end…my php skill stopped there lol.
Any tips / help / explanations etc ill gladly accept.

  • 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-30T20:15:29+00:00Added an answer on May 30, 2026 at 8:15 pm

    Looks like it’s echoing right at the time it preg_replaces, instead of saving it to be echoed later. Try changing:

    echo preg_replace($reg_exUrl, "<a href='{$url[0]}'>{$url[0]}</a> ", $text);
    

    To:

    $text = preg_replace($reg_exUrl, "<a href='{$url[0]}'>{$url[0]}</a> ", $text);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that gives a user id to a utility that then
I have some code that uses the shared gateway pattern to implement an inversion
I have some code that raises PropertyChanged events and I would like to be
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have some code that generates image of a pie chart. It's a general
I have some code that effectively does this : File file = new File(C:\\Program
I have some code that I am putting in the code-behind of a master
I have some code that uses the Oracle function add_months to increment a Date
I have some code that prints out databse values into a repeater control on
I have some code that produces a set of primary key values that I

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.