There is a code:

<?php $a = '<div style="text-align:center;"><!--image_begin:https://dl.site.com/20/NTQ3Nw==/Fists.jpg|--></div>'; preg_match('/image\_begin\:(.+)\|\-\-\>/', $a, $b); print_r($b); Array ( [0] => image_begin:https://dl.site.com/20/NTQ3Nw==/Fists.jpg|--> [1] => https://dl.site.com/20/NTQ3Nw==/Fists.jpg ) 

How to get rid of [0] => image_begin:https://dl.site.com/20/NTQ3Nw==/Fists.jpg|--> ?

That is, as a result, only the URL of the search image is displayed as the only element of the array. I am a regular no expert on this appeal to you.

Closed due to the fact that the essence of the question is not clear to the participants of Wiktor Stribiżew , 0xdb , entithat , yolosora , Jarvis_J Nov 26 '18 at 17:57 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • You can get rid of and not being a connoisseur of regulars: unset($b[0]) . In general, the first element corresponding to the entire template is the normal behavior of preg_match . - Yegor Banin
  • @EgorBanin I’m talking about the means of the preg_match function, without the subsequent formatting of the array. - Ivan
  • You can use affirmations ( php.net/manual/ru/regexp.reference.assertions.php ) and not use exciting subtitles: (?<=image_begin\:).+(?=\|-->) . - Yegor Banin

2 answers 2

How to get rid of [0] => image_begin: https://dl.site.com/20/NTQ3Nw==/Fists.jpg|-- >?

You can use retrospective and advanced checks - they do not capture characters that participate in matches:

 $a = '<div style="text-align:center;"><!--image_begin:https://dl.site.com/20/NTQ3Nw==/Fists.jpg|--></div>'; preg_match('~(?<=_begin:).+?(?=\|-->)~', $a, $b); var_dump($b); 

Result:

 array (size=1) 0 => string 'https://dl.site.com/20/NTQ3Nw==/Fists.jpg' (length=41) 

    http://php.net/manual/ru/function.preg-match.php read about the function. Regularity itself is nothing to do with If you want another array. Create it from $ b [1]