Please tell me how to cut a link of this format.

https://static.site.com/images/common/galleries/id/with_logo/image.jpg 

To get only the id parameter

I get the link from the parser, and the parameter is later used to play the POST request via cURL . I did not find any other ways to pull him out of the page :)

  • for parse_url url usually use parse_url , but here with its help you will only get the entire string of images/.... its entirety. What do you expect as a result here? with_logo ? regulars to help you - teran
  • As a result, expect id . I guessed that I need them, but I am not strong in them) - RedScreed
  • That is, id is a certain set of letters-numbers-dashes? not the word id itself? PS: always give an example of real data - teran
  • Yes, this is just a set of numbers - RedScreed

1 answer 1

 $str = 'https://static.site.com/images/common/galleries/id/with_logo/image.jpg'; $str_arr = explode('/', $str); $id = $str_arr[6]; 

Ps If this is the final link, then this option is suitable. Otherwise, it is better to resort to smarter line explode , rather than just through explode

  • In general, yes, fit, kept him in thoughts. Just thought, there are more elegant, perhaps, and universal ways. - RedScreed
  • In general, it would be good to describe why this is and where it will be used, in this case there will be much more options. explode - the most primitive thing that comes to mind - Alexxosipov
  • Completed the question. But in general, the format of links from page to page does not change. So that should fit - RedScreed
  • For the parser, this is quite enough. If on the donor site the URLs change, then you just need to change the index in the array - Alexxosipov