PHP regex remove words less than 3 characters

# PHP convert string to list of keywords
# PHP transform a text to meta keywords
# Extract keywords from a text string with PHP

PHP regex replace one-letter words

<?php
$str = preg_replace('/\s\w\s/', ' ', $str);
$str = preg_replace('/^\w\s/', '', $str);
$str = preg_replace('/\s\w$/', '', $str);

PHP regex replace two-letters words

<?php
$str = preg_replace('/\s\w\w\s/', ' ', $str);
$str = preg_replace('/^\w\w\s/', '', $str);
$str = preg_replace('/\s\w\w$/', '', $str);

Read more:

– PHP Regex: Remove words less than 3 characters
http://stackoverflow.com/questions/24463814/php-regex-remove-words-less-than-3-characters

– Remove words which consist 3 character using php
http://stackoverflow.com/questions/10619482/remove-words-which-consist-3-character-using-php

– Regex replace one or two letter words
http://stackoverflow.com/questions/6810253/regex-replace-one-or-two-letter-words

– Remove short words and characters from a string in PHP
http://stackoverflow.com/questions/7695016/remove-short-words-and-characters-from-a-string-in-php

PHP preg_match IP addresses in a string

Extract list of IPs from a string, or text file

# regular expression
# preg_match_all

PHP script

<?php
// $example_text = = file_get_contents(dirname(__FILE__) . '/example_file.txt');
$example_text = '
188.40.112.210
162.244.11.73; /toenailfungustreatment.webs.com/
23.95.18.100; 107.168.141.76; /twenteconsult.nl/ and more
104.143.213.189; 192.240.212.82; 23.229.98.188; 23.232.148.73; 91.200.12.8; 91.200.12.44; 104.128.138.33; 162.244.8.75; 216.244.84.44;
!!! 10.240.138.28; 10.240.138.31; 10.240.138.32; Status: private
23.229.98.188 (SEO?)
China 27.159.216.46 www.sexybabe.mobi
*.taoche.com
!!! 212.83.191.173 /animals-sanctuary.com/
!!! 173.254.207.3; ! 45.35.5.48; ! 205.164.9.119; !!! 138.128.53.34; !!! 142.252.113.22; ! 192.225.160.237 /wp-login.php?action=register
China 180.116.3.210
Fr 178.32.12.117|Fr 212.83.191.173 /animals-sanctuary.com/r/www.fwcityvision.com/stats/referrer.html
China 117.169.1.15 /wp-login.php?action=register; /animals-sanctuary.com/
50.117.77.58 /?start=0
50.118.209.98; 23.232.148.194; 66.34.75.60; ! 104.222.217.127 /wp-login.php?action=register; /animals-sanctuary.com/ & more
Trackback pings::: China 117.169.1.175|104.247.121.172|104.247.121.172|155.94.138.77|China 122.96.59.106|89.47.17.209|5.157.62.138
US 204.236.235.245 /freevideocapture.com & more; User Agent: ia_archiver
';

preg_match_all('/\d{2,}\.\d{2,}\.\d{2,}.\d{2,}/', $example_text, $array);

// print_r ($array);

foreach ( $array[0] as $key => $value ) {
echo $value . '<br />';
}

exit;

JavaScript regex and function to check valid URL

<script>
function ValidUrl(str) {
var url_protocol = /^(http|https|ftp):\/\//i;
var url_domain = /\.[a-z][a-z]/i;
var url_ip_v4address = /(\d{1,3}\.){3}\d{1,3}/;
if ( str.trim().length > 8 && url_protocol.test(str) && ( url_domain.test(str) || url_ip_v4address.test(str) ) )
return true; else return false;
}
</script>