Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在显示一个长度不同的字符串,但我只希望它显示前四个字符。不知道我需要添加什么:
<?php if (!empty($book->editions[0]['publication_date'])): ?> <?php print $book->editions[0]['publication_date'] ?> <?php endif; ?>
print substr( $book->editions[0]['publication_date'], 0, 4 );
有关详细信息,请参阅substr 。
您应该使用substr函数。
在您的示例中,它看起来像这样:
print substr($book->editions[0]['publication_date'], 0, 4);
使用substr
substr( $book->editions[0]['publication_date'],0,4);