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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:01:59+00:00 2026-06-07T14:01:59+00:00

The goal is to check if a string is a URL, no regex needed.

  • 0

The goal is to check if a string is a URL, no regex needed.

I have a form that lets users upload an image or add an image from a URL.

I get:

van_gogh_shoes.jpg

or

http://t2.gstatic.com/images?q=tbn:ANd9GcR2YNtlcmDDBpseEqUkMhe7-netq7RL2u_bw3_34VwB-Tsv2V-B

Users can add just 1 image, either uploaded or URL. So in mysql I’m updating the same column named entry_image with one of the values above.

When displaying images I need to check in the simplest way possible if the value from entry_image column is a URL. If so, display the full URL otherwise my own path to the uploaded image.

<img src="<?php (filter_var($row->entry_image, FILTER_VALIDATE_URL)) ? $row->entry_image : "uploads/entries/{$row->user_id}/{$row->entry_image} ?>">

I’m using FILTER_VALIDATE_URL which seems to work but as with most things I didn’t use before I’m not sure if it’s the best solution.. What are your thoughts?

I’m trying to avoid regex or other heavy validation codes when displaying images because I’m already validating the values when entering data to mysql. Please share a simpler solution if it exists.

  • 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-07T14:02:00+00:00Added an answer on June 7, 2026 at 2:02 pm

    filter_var() is the best solution for this. Thumbs up for not wanting a regex as a solution.

    Other than that, I just want to point out that transferring the image file from an external URL to your server is a better way (in my opinion). It will keep you from problems like deleted external images, and connection issues with external servers. You won’t also have to worry about validating URLs. This is just a suggestion though.

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

Sidebar

Related Questions

Goal: Produce an Excel document with information from 3 associated models that is similar
How would you implement that check? You have N parameters for a stored procedure.
Goal: Expose a simple WCF service that would take as a parameter a string
My ultimate goal is to do this programmatically, but as a sanity check I'm
Goal : I wants when I drag image it become fade so we can
Goal is to make a dialog that appears on menu_key pressed, but it keeps
The title explains all... I have this snippet of code in my application: String
The goal is to avoid copying the string data when I need a const
I have a string like this: // string1 horse|cow|goat|zebra| and another string like this:
I wanted to check that typeid is evaluated at compile time when used with

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.