Substr get_post_meta数据?
How can I limit the text to say 100 characters from the get_post_meta tag?
I need to grab the text in this style:
<?php echo get_post_meta($relationship->ID, 'company_description', true ); ?>
This is how I would normally limit the text but I don't know how to combine it with the syntax above:
<?php echo substr($fields->company_description,0,100) . "..."; ?>
如何将文本限制为从get_post_meta标记中说出100个字符? p>
&lt;?php echo get_post_meta($ relationship-&gt; ID,'company_description',true); ?&GT;
code> pre>
这就是我通常限制文本的方法,但我不知道如何将其与上述语法结合起来: p>
&lt;?php echo substr($ fields-&gt; company_description,0,100)。 “......”; ?&gt;
code> pre>
div>
The most readable way:
$text = get_post_meta($relationship->ID, 'company_description', true);
echo substr($text, 0, 100) . "...";
Then of course, you could also nest the function calls, which probably sucks in terms of readability:
echo substr(get_post_meta($relationship->ID, 'company_description', true), 0, 100) . "...";
By the way: If company_description
might contain raw HTML, you'll probably want to run strip_tags()
over it before getting a substring – not stripping HTML would get you in trouble in the long run otherwise.
$text = strip_tags(get_post_meta($relationship->ID, 'company_description', true));
echo substr($text, 0, 100) . "...";