Replace Swedish characters åäö in string
This is some ways of removing the Swedish characters åäö in a string.
This is some ways of removing the Swedish characters åäö in a string.
This is how you can split a text by its natural paragraphs using line break characters backslash r and backslash n (\r\n). This script looks for three following line breaks and add it to an array for other actions. This code is ripped out of its context in a Drupal module.
$search = array ('/'.chr(128).'/',
'/'.chr(157).'/',
'/'.chr(160).'/');
$replace = array ('', '', ' ');
$node_body = preg_replace($search, $replace, $node_body);This expression can be used when you want to validate a pattern containing houres and minutes or just hours or just minutes. The time pattern to accept is:
This is how you can filter a text and load it into an array. This function converts all words into lower-case, removes all HTML tags, junk characters and numbers, explode it in to an array and finally removes duplicates.
| Regular Expression | Will match... |
| foo | The string "foo" |
| ^foo | "foo" at the start of a string |
| foo$ | "foo" at the end of a string |
This is how you find a whole word by its boundary when the word is starting with åäö. The usual boundary expression can handle if Swedish characters is in the string but not if it starts (or ends) the word. That means that a word like "öknen" can't be found but a word like "behöver" will be found.
<?php
$text = "I öknen behöver man vatten";
$keyword = "öknen";
//$keyword = "behöver";
?>This is the usual boundary expression
This is how you find an exact word in some text string. The "\b" is for finding the words boundary and the "i" is to let the search be case insensitive.
<?php
$matches = array();
$text = "Play poker"; //Some text
$keyword = "Poker";
preg_match("/\b".$keyword."\b/i", $text, $matches, PREG_OFFSET_CAPTURE);
foreach ($matches as $key => $value) {
echo "<br>$key => $value";
}
?>
Array
(
[0] => Array
(
[0] => poker
[1] => 5
)
)This is how you can validate an URL by examining the pattern.
<?php
function validateURL($url) {
$pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/';
return preg_match($pattern, $url);
}
?>
Or from Drupal 6
/**
* Verify the syntax of the given URL.
*
* This function should only be used on actual URLs.
This function checks if a given URL is valid by using fsockopen.
function is_valid_url ($url){
$url = @parse_url($url);
if ( ! $url) {
return false;
}
$url = array_map('trim', $url);
$url['port'] = (!isset($url['port'])) ? 80 : (int)$url['port'];
$path = (isset($url['path'])) ? $url['path'] : '';
if ($path == ''){
$path = '/';
}
$path .= ( isset ( $url['query'] ) ) ?