Search Marketing

   
   

Matching Characters in a Text String with PHP

Thu Nov 05, 2009 6:58 pm
<<     >>
Comments: 0 Views: 178

If you have a block of text and want to match certain characters or words then mb_ereg_match() works great to find any instance or instances of the occurrence you are looking for.

There are an unbelieveable number of reasons you might want to find something in a block of text. Basically if you find something you can then change it. You could change the character of links, html, relative links to absolute links, change a's to b's or anything else. But first you need to find what you are looking for.

Using the following function you could find anything in a text block:

$string = "programming is good";

$match = "is";

$example = mb_ereg_match(".*$match", "$string");

The result would be true, because there is an "is" in the string.

Lets assume that in the example you want to make a note if any specific occurrences of "is" are found in the text.

if($example == 1) // 1,true 0, false
{
echo "there is a match in the string";
// then do - insert code
}

Note: The wildcard (*) character says to match anything in the string, but you may remove it to match more specific parts of the text block.



Comments
Name:
*
URL: http: (ex. cnn.com)
Comment:
*
Number:
Math (28 + 5)
* required
SubCategories
Regular Expressions

© 2019 Christonium LLC

Christonium.com
|
Terms of Use
|
Privacy
ccc