• Resolved aintnosin

    (@aintnosin)


    okay, I’m running into a weird problem. I’m using preg_match_all to decode some shortcode input into pairs of values and numbers. I tried posting the question over a stack overflow and they were only interested in blasting my regex pattern.

    Here is my test function:

    function WTF($atts, $content) {
    	$pattern = '%([\w&\s]+)[:,\|\/]{1}(\d+)([\|,\|\/]{0,1})%';
    	$contentX = 'Sex:3,Drugs,4,Violence:1,Rock & Roll,5';
    
    	preg_match_all($pattern, $content, $xmatch, PREG_SET_ORDER);
    	preg_match_all($pattern, $contentX, $ymatch, PREG_SET_ORDER);
    
    	var_dump($content);
    	var_dump($contentX);
    
    	$ret = '<pre>' . print_r($xmatch, TRUE);
    	$ret .= "\n" . print_r($ymatch, TRUE);
    	if ($content === $contentX) {
    		$ret .= "\n" . 'Match!';
    	} else {
    		$ret .= "\nNo Match!";
    	}
    	$ret .= '</pre>';
    
    	return $ret;
    }

    The problem is simple: the $content var should have the same text as the $contentX var in the function. I literally cut and pasted the same text into my test post.

    However, when the preg_match_all function returns the results from $content, the last string is just “Roll”

    For $contentX var, it returns “Rock & Roll.” Same text, same pattern. Different results.

    the if statement indicates that $content !== $contentX

    The var_dump for $content is: string(43) "Sex:3,Drugs,4,Violence:1,Rock & Roll,5"
    The var_dump for $contentX is string(38) "Sex:3,Drugs,4,Violence:1,Rock & Roll,5"

    $content is 5 characters longer, but there no visible difference.

    Thoughts?

Viewing 1 replies (of 1 total)
  • Thread Starter aintnosin

    (@aintnosin)

    It appears I need to run the $content through html_entity_decode. The “&” was now “&#038”

Viewing 1 replies (of 1 total)
  • The topic ‘Shortcode $content different than declared string var with same text.’ is closed to new replies.