php – regular expression to get all urls in a string except one url
Question
I have an array of urls
urls = [ 'example.co.uk/nz', 'example.com/us', 'exclude.example.co.uk' ];
now I wanted to do some manipulations with the above 2 urls and want to skip the third. here is my code.
function xyz($url) {
$url_locale = preg_match( '#(.co.uk|.com)/([a-zA-Z]{2})/#', $url, $matches );
if ( ! empty( $matches[2] ) ) {
// do something
} else {
// do something else
}
}
xyz( $url[0] ); //do something
xyz( $url[1] ); //do something
xyz( $url[2] ); //do something else
so basically it should exclude the exclude.example.co.uk from the preg_match
0
1 year
2022-06-22T02:33:20-05:00
2022-06-22T02:33:20-05:00 0 Answers
0 views
0
Leave an answer