Understand how to extract substrings in PHP
P粉257342166
P粉257342166 2023-08-07 17:24:13
0
1
536
<p>I have a URL in the format </p> <pre class="brush:php;toolbar:false;">$string ='https://test.com/uploads/2023/02/06/1/18413/themes/2725/images/dvd_jacket_pdf/dvd_jacket_20630 .pdf';</pre> <p>I need to extract 2725, which is a topic ID, in the application. Can I do this in PHP using regular expressions? I think the logic should be to extract the characters between the subject string and //. </p> <pre class="brush:php;toolbar:false;">preg_match('#themes/(.d )#', $string, $check);</pre> <p>I also want to add slashes to this regex. </p>
P粉257342166
P粉257342166

reply all(1)
P粉237029457

You don't need to use a slash, and you have an extra dot in the pattern. Just use this:

$string = 'https://test.com/uploads/2023/02/06/1/18413/themes/2725/images/dvd_jacket_pdf/dvd_jacket_20630.pdf';
if(preg_match('#themes/(\d+)#', $string, $check))
    echo $check[1]; 
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template