Solved

PHP  regex(?)  call needed

Posted on 2014-01-21
2
366 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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