Last active
March 11, 2018 08:37
-
-
Save yuriitaran/84c3213579f228e0faaccaa1f48553a0 to your computer and use it in GitHub Desktop.
Reg_exp examples /preg_match / regexp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // clean phone number for link "tel:1234567" | |
| preg_replace("#(?<=\d)[\s-]+(?=\d)#","", $number) | |
| // phone number | |
| preg_match('/^\+[0-9\-\s]*(\([0-9]+\))?[0-9\-\s]*$/', $number) | |
| preg_match("/[0-9a-z]+@[a-z.]/", $email) | |
| // phone number with WP ACF | |
| <?php if (preg_match('/^[0-9\-\s]*(\([0-9]+\))?[0-9\-\s]*$/', $phone)): ?> | |
| <span><a href="tel:<?php echo preg_replace('/\s+/', '', $phone); ?>"><?php echo $phone; ?></a></span> | |
| <?php else: ?> | |
| <span><?php echo $phone; ?></span> | |
| <?php endif ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment