for some weird reason, this is not working for me when it comes to reading my custom field characters, but when i test it myself, it works??
<?php $arabic = "?????? ????? ?? ????? ?????"; ?>
<?php echo strlen(utf8_decode($arabic)); ?>
the above strlen function enables it to count utf characters that have more than one byte as one character. So above, its count was “27” characters.
but when I adopt the same idea for my WP template, strlen counts my summary as “5” characters only, when i know that each summary may have 100+ characters. Here’s the code:
<?php $recent = new WP_Query("cat=3&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<?php $image = get_post_meta($post->ID, 'imageThumb', true); ?>
<?php $imageURL = get_post_custom_values("imageBig"); ?>
<?php $summary = get_post_custom_values("articleSummary"); ?>
<div id="articleSnippet">
<div id="articleImage"><a href="<?php the_permalink() ?>"><img src="<?php echo $imageURL[0]; ?>" width="156" height="78" /></a></div>
<div id="articleSummary"><a href="<?php the_permalink() ?>"><strong><?php the_title() ?></strong>
<br /><?php if (strlen(utf8_decode($summary)) > 40) { echo substr(get_post_custom($before = '', $after = '', FALSE), 0, 40) . '...'; } else { echo $summary[0]; } ?></a></div>
</div>
<?php endwhile; ?>
Am I writing this wrong?