$pattern = "/.{80}/\S/"; - another regex question

From: lawrence (lkrubner_at_geocities.com)
Date: 03/29/04


Date: 29 Mar 2004 09:09:15 -0800

When users enter urls or other long strings it can destroy the
formatting of a page. A long url, posted in a comment, can cause page
distortions that make the page unreadable, till the website owner logs in
and deletes the comment. To protect against that, I'd like to break up
long strings in the comments (anything submitted by anonymous sources).

One thing I'd like to add to the following function is the ability to
break up long strings - anything more than 80 chars should have a
space inserted. I want something like this:

.{80}

but that would include white space. How do you say "everything but
white space" in regex? I realize I'm supposed to use "/\S/" but I
don't understand how. Is this correct:

$pattern = "/.{80}/\S/";
$replaceWith = $pattern." ";

 $string = eregi_replace($pattern, $replaceWith, $string);

function processStringForPublic($string, $return=0,
$class="mcParagraph") {
 // 04-01-03 - this function is to replace PHP's built in nl2br()
function with something better because
 // graphic designers give me grief about my code using <br> instead
of <p>.
 // 03-31-03 - "for public" means we use the string to send stuff to
website visitors.
 // The opposite of "forPublic" is "forEdit".

 // 04-05-03 - We need to turn this into an array, using explode, so
first we need to
 // get out whatever symbol we'll use to explode() the string.
 $string = str_replace("`", "#x#x~~x#", $string);
 $pattern = "\r?\n[ \t\r]*\n";
 $string = eregi_replace($pattern, "`", $string);
 $stringArray = explode("`", $string);

 // Make sure the string is empty so we can refill it.
 $string = "";

 // 04-04-03 - Now we need a for loop to go through and give a unique
name to every paragraph.
 for ($i=0; $i < count($stringArray); $i++) {
  $name = makeDisplayTextFromString($stringArray[$i]);

  // 04-23-03 - the $i==0 line is so that we don't print </p> as the
very first thing. Bad HTML. No validation that route! - lk
  if ($i == 0) {
   // 04-27-03 - is there any trouble with the id and name being the
same?
   $string .= "<p id=\"$name\" name=\"$name\" class=\"$class\">";
  } else {
   // 04-05-03 - in this next line, the &nbsp; is needed so these
paragraphs can be used for spacing. An empty paragraph won't create a
space
   $string .= "&nbsp;</p><p id=\"$name\" name=\"$name\"
class=\"$class\">";
  }
  $stringArray[$i] = str_replace("\n", "<br/>", $stringArray[$i]);
  $string .= $stringArray[$i];
  $string .= "\n\n";
 }
 $string .= "</p>";
 $string = str_replace("#x#x~~x#", "`", $string);

 $string = processHtmlTagEndings($string, "<i>");
 $string = processHtmlTagEndings($string, "<b>");
 $string = processHtmlTagEndings($string, "<u>");
 $string = processHtmlTagEndings($string, "<em>");
 $string = processHtmlTagEndings($string, "<strong>");
 $string = processHtmlTagEndings($string, "<center>");
 $string = processHtmlTagEndings($string, "<a ");
 $string = processHtmlTagEndings($string, "<div ");
 $string = processHtmlTagEndings($string, "<span ");
 $string = processHtmlTagEndings($string, "<p ");
 $string = processHtmlTagEndings($string, "<ul ");
 $string = processHtmlTagEndings($string, "<div ");
 $string = processHtmlTagEndings($string, "<span ");
 $string = processHtmlTagEndings($string, "<ol ");
 $string = processHtmlTagEndings($string, "<span ");
 $string = processHtmlTagEndings($string, "<p ");
 $string = processHtmlTagEndings($string, "<p>");
 $string = processHtmlTagEndings($string, "<div>");
 $string = processHtmlTagEndings($string, "<span>");
 $string = processHtmlTagEndings($string, "<ul>");
 $string = processHtmlTagEndings($string, "<div>");
 $string = processHtmlTagEndings($string, "<span>");
 $string = processHtmlTagEndings($string, "<ol>");
 
 if ($return) {
  return $string;
 } else { echo $string;
 }
}



Relevant Pages

  • Re: Email Merge in Word
    ... Different software packages can treat "null", "a string set to ''", and "a string containing white space differently, and may also treat variable-length and fixed-length data differently in this respect. ... Also, when I set up my query, I selected the criteria for the email address field "is not null", and there are still some blank records with no emails. ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Email Merge in Word
    ... WHERE mystring is not null AND trim'' ... If the address looks blank but len) is> 0 then the field probably contains invisible non-space characters. ... Different software packages can treat "null", "a string set to ''", and "a string containing white space differently, and may also treat variable-length and fixed-length data differently in this respect. ...
    (microsoft.public.word.mailmerge.fields)
  • Re: String parsing program
    ... there can be only white space till a digit is reached and once a digit ... string should only contain 1 number in my program. ... use the signed strtol function. ...
    (comp.lang.c)
  • Re: strange behaviour sys.argv
    ... different rules for different shells. ... a string extending from just after the first double quote to ... white space) unquoted text 'fCannotTakeover' appended ... Quotes resulting from the substitution of $TRAP are also protected ...
    (comp.lang.python)
  • Re: string trim not trimming special space characters
    ... Since the [string trim*] commands lets you name exactly the character ... While the documentation is clear and there is a viable workaround, this seems seems more like a case of something being missed when we went from ASCII to Unicode. ... string trim's definition of white space should be a superset of string is space. ...
    (comp.lang.tcl)