Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex for identifying all kinds of spaces to be used as a delimiter for exploding a string into an array?
    primarykey
    data
    text
    <p>I'm not proficient with regular expressions so when I needed to identify if a paragraph (post excerpt in Wordpress) started with the word "by" and if it did to apply a CSS class to the word "by" and the next two words I did so by exploding the string into an array delimited by space, manipulating the array and then imploding it.</p> <p>Something weird is happening though. The " " delimiter doesn't work on all spaces (and there are no double spaces being used). Are there multiple versions of the space character out there? </p> <p>Shouldn't my whole site have the same encoding type and therefore there only be one space character?</p> <p>If I edit one of the problem posts and delete the first couple of spaces and replace them with new spaces, the code works fine.</p> <p>My code is below (I know I declared a lot of variables): The part under the elseif{ is specifically what I was describing, but I pasted the whole conditional block for reference.</p> <pre><code>$byLine = strtolower(string_limit_words(get_the_excerpt(),1)); $storySnippet = string_limit_words(get_the_excerpt(),16); $storyExplode = explode(' ', $storySnippet); if (($byLine=="by") &amp;&amp; strtolower($storyExplode[3])=="and") { $storySlice = array_slice($storyExplode, 6); $storyLast = implode(' ', $storySlice); ?&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" class="byline"&gt; &lt;?php echo string_limit_words(get_the_excerpt(),6); ?&gt;&lt;/a&gt; &lt;?php echo " ".$storyLast."&amp;hellip;"; } elseif ($byLine=="by") { $storySlice = array_slice($storyExplode, 3); $storyLast = implode(' ', $storySlice); ?&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" style="color:#888;font-style:italic;font-size:90%;"&gt; &lt;?php echo string_limit_words(get_the_excerpt(),3); ?&gt;&lt;/a&gt; &lt;?php echo" ".$storyLast."&amp;hellip;"; } else { echo string_limit_words(get_the_excerpt(),16)."&amp;hellip;"; } </code></pre> <p>EDIT:</p> <p>Currently using <strong>preg_split('|\s+|', $storySnippet)</strong> instead of exploding the array with ' ', but I'm still experiencing the same problem. </p> <p><a href="http://advocatedaily.com" rel="nofollow">Live on adovatedaily.com, 3rd entry under the "opinion" column</a> halfway down the page.</p> <p>EDITx2:</p> <p>Converted one of the problem strings to hex. "By Jen" converts to <strong>4279c2a04a656e</strong>. There's no <strong>20</strong> in there and there appears to be an extra character.. what gives?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload