Solved

PHP  regex(?)  call needed

Posted on 2014-01-21
2
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

752 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