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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:39:10+00:00 2026-05-25T18:39:10+00:00

I am working with a regular expression in PHP. I have the following string:

  • 0

I am working with a regular expression in PHP. I have the following string:

<img 
src="/files/admin/hotel_website.gif" alt="Go To The Hotel's Web 
Site" align="absmiddle" border="0" class="hotel_icon" />

This string contains carriage return and line feed characters.

I want my regular expression to replace html img tags with IMG but this does not work with the above text.

I discovered it contained these characters by looping through each character in the string and printing out the hexadecimal representation which can be found here (http://pastebin.com/ViNdBsRV).

Here is my regular expression:

strip_tags(preg_replace('/^\s*<img\s*.*\/?>\s*$/i', '[IMG]', $test));

Appreciate the help.

  • 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-25T18:39:11+00:00Added an answer on May 25, 2026 at 6:39 pm

    This:

    preg_replace("#<img.+?/>#is", '[IMG]', $test)
    

    Personally when I’m making a regular expression I always try to go the shortest/simplest.
    Here you want to replace an entire tag, which starts with ‘<img‘ and ends with ‘/>‘, ‘.+?‘ is a non greedy (lazy) catch.
    And for the modifiers ‘i‘ for the case and ‘s‘ to . the possibility to be a new lines.

    More on greedyness vs lazyness : http://www.regular-expressions.info/repeat.html
    More on modifiers: http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

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

Sidebar

Related Questions

i have a string with optional substrings and i was looking/working for/on regular expression
I have been working on my date regular expression all day... I want a
I have a little problem with my regular expression, that I use in PHP.
I am doing a string parsing problem in PHP. I want a regular expression
i've been working on this question since yesterday, i have the following code.. <?php
I am working on writing a Perl-compatible regular expression in PHP to check whether
Is the @ symbol sometimes used to surround a PHP regular expression? I'm working
The following regular expression is working with Internet Explorer, but it does not work Firefox
I have a regular expression in Ruby that isn't working properly in multiline mode.
Recently programming in PHP, I thought I had a working Perl regular expression but

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.