Jump to content

PHP String

- - - - -

  • Please log in to reply
1 reply to this topic

#1
shivam

shivam

    Newbie

  • Members
  • PipPip
  • 27 posts
I have an array of 66 elements which containing the URL of the particular website.

I want to create an array of those elements which start from a particular address ( e.g. "http://www.example.com/images/"). what is the best method to do this, which function is to be used without using loop ??

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Assuming $arrayOfUrls is your array of 66 elements.
$outArray = array();
$search = "http://www.example.com/images/";

foreach($arrayOfUrls as $url) {
  if(substr($url, 0, strlen($search))  == $search) {
    $outArray[] = $url; //push $url to $outArray
  }
}

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users