I am trying to create a simple function, maybe using Regular Expressions, that would let me search text for a substring of continuous characters. For example, I don't want a word or URL etc. to exceed 25 characters in length. The most important thing is that the string is identified and replaced.
Example:
$str = "this is a simple string of cxdhbnmkgfhgfsa/:$&@xxstrehxvifdsa that I want to check";
I want to be able to locate the long substring within $str and replace it with something else. Any help will be appreciated.
Thanks,
Ethan
Need to search a string for a substring of a certain length
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Need to search a string for a substring of a certain length
One way:eawade wrote:I am trying to create a simple function, maybe using Regular Expressions, that would let me search text for a substring of continuous characters. For example, I don't want a word or URL etc. to exceed 25 characters in length. The most important thing is that the string is identified and replaced.
Example:
$str = "this is a simple string of cxdhbnmkgfhgfsa/:$&@xxstrehxvifdsa that I want to check";
I want to be able to locate the long substring within $str and replace it with something else. Any help will be appreciated.
Thanks,
Ethan
Code: Select all
$str = preg_replace('/[^\s]{25,}/', 'SOMETHING ELSE', $str);mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.