php - Regex for identifying all kinds of spaces to be used as a delimiter for exploding a string into an array? -
i'm not proficient regular expressions when needed identify if paragraph (post excerpt in wordpress) started word "by" , if did apply css class word "by" , next 2 words did exploding string array delimited space, manipulating array , imploding it.
something weird happening though. " " delimiter doesn't work on spaces (and there no double spaces being used). there multiple versions of space character out there?
shouldn't whole site have same encoding type , therefore there 1 space character?
if edit 1 of problem posts , delete first couple of spaces , replace them new spaces, code works fine.
my code below (i know declared lot of variables): part under elseif{ describing, pasted whole conditional block reference.
$byline = strtolower(string_limit_words(get_the_excerpt(),1)); $storysnippet = string_limit_words(get_the_excerpt(),16); $storyexplode = explode(' ', $storysnippet); if (($byline=="by") && strtolower($storyexplode[3])=="and") { $storyslice = array_slice($storyexplode, 6); $storylast = implode(' ', $storyslice); ?> <a href="<?php the_permalink(); ?>" class="byline"> <?php echo string_limit_words(get_the_excerpt(),6); ?></a> <?php echo " ".$storylast."…"; } elseif ($byline=="by") { $storyslice = array_slice($storyexplode, 3); $storylast = implode(' ', $storyslice); ?> <a href="<?php the_permalink(); ?>" style="color:#888;font-style:italic;font-size:90%;"> <?php echo string_limit_words(get_the_excerpt(),3); ?></a> <?php echo" ".$storylast."…"; } else { echo string_limit_words(get_the_excerpt(),16)."…"; } edit:
currently using preg_split('|\s+|', $storysnippet) instead of exploding array ' ', i'm still experiencing same problem.
live on adovatedaily.com, 3rd entry under "opinion" column halfway down page.
editx2:
converted 1 of problem strings hex. "by jen" converts 4279c2a04a656e. there's no 20 in there , there appears character.. gives?
thanks comments discovered space in question causing problem non breaking space (c2a0 in hex).
i replaced string's white space regular spaces using line below, solving problem.
$spacedexcerpt = preg_replace('/\xc2\xa0/', ' ', get_the_excerpt());
Comments
Post a Comment