Guest User

Untitled

a guest
Nov 20th, 2017
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5. <title>Основы работы с регулярными выражениями</title>
  6. <link href="../../css/reset.css" rel="stylesheet"/>
  7. <link href="../../css/style.css" rel="stylesheet"/>
  8. <style>
  9. .text_red_bold{
  10. color: red;
  11. font-weight: bold;
  12. }
  13. </style>
  14.  
  15. </head>
  16. <body>
  17. <div id="content">
  18. <div class="job">
  19. <div class="jobTitle">
  20. Регулярное выражение, проверяющее, является ли строка корректным e-mail адресом.
  21. </div>
  22. <div class="jobContent">
  23. <?php
  24. "[email protected]", "v.v.pupkin12@firma_mail.com", "[email protected]",
  25. echo "До применения : <br>";
  26. for ($i = 0; $i < count($array); $i++) {
  27. echo $array[$i];
  28. echo '<br />';
  29. }
  30. echo "<br> После применения : <br>";
  31.  
  32. for ($i = 0; $i < count($array); $i++) {
  33. if (filter_var($array[$i], FILTER_VALIDATE_EMAIL)) {
  34. echo $array[$i];
  35. echo '<br />';
  36. }
  37. }
  38. ?>
  39. </div>
  40. </div>
  41. <div class="job">
  42. <div class="jobTitle">
  43. <p>Регулярное выражение, удаляющее из текста HTML-комментарии</p>
  44. </div>
  45. <div class="jobContent">
  46. <?php
  47. $html = 'div class="item"<!--Комментарий-->/div';
  48. echo preg_replace('|<!--(?!<!)[^\[>].*?-->|im', "", $html);
  49. ?>
  50. </div>
  51. </div>
  52. <div class="job">
  53. <div class="jobTitle">
  54. <p>Регулярное выражение, очищающее текст от HTML-тегов.</p>
  55. </div>
  56. <div class="jobContent">
  57. <?php
  58. $html = '<h1>Текст для проверки</h1>';
  59. echo preg_replace('/<[^>]*>/', "", $html);
  60. ?>
  61. </div>
  62. </div>
  63.  
  64.  
  65. <div class="job">
  66. <div class="jobTitle">
  67. <p>Регулярное выражение, выделяющее красным жирным шрифтом все слова с длиной в 5 и более символов, состоящие только из заглавных букв....</p>
  68. </div>
  69. <div class="jobContent">
  70. <?php
  71. $regExp = "|([A-Z]{1,3})|";
  72. $str = "the QUICK BROWN fox jumps over the lazy dog";
  73. $output = "";
  74. $parts = explode(' ', $str);
  75. foreach($parts as $part) {
  76. if (preg_match_all($regExp, $part, $array)) {
  77. $output = $output . "<span style=\"color: red; font-weight: bold;\">" . $part . "</span>" . ' ';
  78. } else {
  79. $output = $output . $part . ' ';
  80. }
  81. }
  82.  
  83. $text = 'the QUICK BROWN fox jumps over the lazy dog';
  84. $text = preg_replace('|(\W[A-Z]{1,3}\W)|m', '<span class="text_red_bold">${1}</span>', $text);
  85. // $text = preg_replace('|([A-Z]{5})|m', '<span class="text_red_bold">${1}</span>', $text);
  86.  
  87. echo $text;
  88. ?>
  89. </div>
  90. </div>
  91.  
  92.  
  93. </div>
  94.  
  95. </body>
  96. </html>
Advertisement
Add Comment
Please, Sign In to add comment