string

How to find exact match of word in a string

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
        )

)

Upper case first in SQL SELECT

This query selects a string from database containing both upper case (STOCKHOLM) and lower case (stockholm) characters and present it as upper case first (Stockholm), and removes duplicates.

<?php
$sql
= "SELECT DISTINCT CONCAT(UPPER(LEFT(LOWER(city_name), 1)), SUBSTRING(LOWER(city_name), 2)) AS city FROM city WHERE 1";
?>

Pages