Solved

PHP  regex(?)  call needed

Posted on 2014-01-21
2
361 Views
Last Modified: 2014-01-22
i have a $string  (max length, say 100 chars) that is (english) text/paragraph that can
contain alpha/numeric/punctuation/linebreaks/hyphens/apostrophe/etc.

i'd like a statement that determines  yes or no   are there  "words" (azAZ09-_')  that exist that are longer than $MaxLength characters  without an intervening  word separator (i.e., non word character).
THe particulars are somewhat flexible for exact definition of "word" and "separator"

is there some sort of regex (or other) PHP call that can evaluate  $String  for  words > $MaxLength

thanks!
0
Comment
Question by:willsherwood
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 39799099
This seems to work nicely:
if (preg_match("/[\w\-']{".($MaxLength+1)."}/s", $string)) {
  print "A word is too long\n";
} else {
  print "You're all good, bro\n";
}

Open in new window

0
 

Author Closing Comment

by:willsherwood
ID: 39799610
very concise,  MANY THANKS!!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now