We have a line for example:

Описание работы 4 [gallery ids="781,780"] 

From here you need to get IDshniki

I am trying to get them using the following expression:

$ids = preg_replace('@.*\[gallery ids="([0-9,]+?)"]@m', '$1', $post->post_content);

In my understanding, it should be 781,780, but something went wrong ... I understand the problem in the line breaks, but I use the m flag. In general, who has the version, what's wrong? :)

    1 answer 1

    If I understand correctly, then you need to do so (if only one ID):

     preg_match('/\[gallery ids="([^"]+)"\]/', $input_line, $output_array); 

    In $ output_array [1] it will be 781,780 or if several

     preg_match_all('/\[gallery ids="([^"]+)"\]/', $input_lines, $output_array); 

    then all output IDs in $ output_array [1]

    preg_replace - it replaces the regular expression in the text, i.e. does a completely different

    • Super. Thanks for what you need :) I did not correctly imagine the work preg_replace - Pavel