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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:51:22+00:00 2026-05-30T07:51:22+00:00

Array { [0] => http://abc.com/video/ghgh23; [1] => http://smtech.com/file/mwerq2; } I want to replace the

  • 0
Array {
    [0] => http://abc.com/video/ghgh23;
    [1] => http://smtech.com/file/mwerq2;
}

I want to replace the content between /sometext/ from the above array. Like I want to replace video, file with abc.

  • 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-30T07:51:23+00:00Added an answer on May 30, 2026 at 7:51 am

    You don’t need to loop over every element of the array, str_replace can take an array to replace with:

    $myArray = str_replace(array('/video/', '/file/'), '/abc/', $myArray);
    

    However, based on your question, you might want to replace the first path segment, and not a specific index. So to do that:

    $myArray = preg_replace('((?<!/)/([^/]+)/)', '/abc/', $myArray);
    

    That will replace the first path element of every URL in $myArray with /abc/…

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

Sidebar

Related Questions

I want to download few HTML pages from http://abc.com/view_page.aspx?ID= The ID is from an
<?php $url = http://website.com/folder/index.php; $data = array('id' => 'R98s', 'name' => 'Bob', 'content' =>
In a remote site, there is a HTML file (say http://www.example.com/abc.html ), which reads:
Thanks in advance. I fetch image url in array. myarray = { http://www.abc.com/uploads/sarab.jpg, ....
According to [MSDN: Array usage guidelines]( http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx) : Array Valued Properties You should use
From: http://ejohn.org/apps/learn/#2 Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object =
The current content of this google docs page is: alt text http://www.deviantsart.com/upload/i9k01q.png However, when
This is my code: function get_remote_file_to_cache(){ $sites_array = array(http://www.php.net, http://www.engadget.com, http://www.google.se, http://arstechnica.com, http://wired.com); $the_site=
I have an array of file-path strings like this videos/funny/jelloman.wmv videos/funny/bellydance.flv videos/abc.mp4 videos/june.mp4 videos/cleaver.mp4
I want to return an array of Strings in the form abc#xyz#ghi#tru (where #

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.