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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:52:48+00:00 2026-05-17T00:52:48+00:00

preg_replace(‘/http:///ftp:///’, ‘https://’, $value); http:// and ftp:// inside $value should be replaced with https:// This

  • 0
preg_replace('/http:///ftp:///', 'https://', $value);

http:// and ftp:// inside $value should be replaced with https://

This code gives error:

preg_replace() [function.preg-replace]: Unknown modifier '/' 

What is a true regex for this task?

  • 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-17T00:52:49+00:00Added an answer on May 17, 2026 at 12:52 am

    Try using a different delimiter, say #:

    preg_replace('#http://|ftp://#', 'https://', $value);
    

    or (less recommended) escape every occurrence of the delimiter in the regex:

    preg_replace('/http:\/\/|ftp:\/\//', 'https://', $value);
    

    Also you are searching for the pattern http:///ftp:// which really does not make much sense, may be you meant http://|ftp://.

    You can make your regex shorter as:

    preg_replace('#(?:http|ftp)#', 'https', $value);
    

    Understanding the error: Unknown modifier '/'

    In your regex '/http:///ftp:///', the first / is considered as starting delimiter and the / after the : is considered as the ending delimiter. Now we know we can provide modifier to the regex to alter its default behavior. Some such modifiers are:

    • i : to make the matching case
      insensitive
    • m : multi-line searching

    But what PHP sees after the closing delimiter is another / and tries to interpret it as a modifier but fails, resulting in the error.

    preg_replace returns the altered string.

    $value = 'http://foo.com';
    $value = preg_replace('#http://|ftp://#', 'https://', $value);
    // $value is now https://foo.com
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function anchor($text) { return preg_replace('#\&gt;\&gt;([0-9]+)#','<span class=anchor><a href=#$1>>>$1</a></span>', $text); } This piece of code is
preg_replace_callback( /[0-9]*/, array( &$this, '_getPHPNumber' ), $code ); private function _getPHPNumber( $matches ) {
Here's a simple preg_replace $string = 'src=index.php'; $string = preg_replace(/(src=('|\)+[^(http:|https:)])/i, src=\http://domain.com/, $string); echo $string;
I need help converting eregi_replace to preg_replace (since in PHP5 it's depreciated): function makeClickableLinks($text)
What are the differences between preg_replace() and preg_filter() ? In which situations should I
Example preg_replace('/\{[a-zA-Z.,\(\)0-9]+\}/', 'Replaced', 'Lorem ipsum dolor sit {tag1({tag2()})}, consectetur adipiscing elit.'); The result: Lorem
preg_replace (/(\p{P})/, ' ', $str) removes apostrophes, and it should not. Please help
Why does this preg_replace to remove HTML entities not work? // Remove all HTML
I have this regex: preg_replace( '/\['.$key.'\] = (.+?);/is', '['.$key.'] = '.$newValue.';', $contents); It writes
I've small preg_replace problem. I need to resize iframe code output so I'm using

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.