I have string /ro/weather-kyiv-4944/
.Need get ro
in this string.
I used preg_match
php
preg_match('\/(ro)\/', $url, $matches);
result null. Help me pls guys.
Upd: need ro
write in variable
I think you are missing your delimiter characters.
Using #
or $
as delimiters is useful because you won't have to escape your /
slashes.
Try the following:
preg_match('#/(?<language>.*?)/#', '/ro/weather-kyiv-4944/', $matches);
print_r($matches);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.