简体   繁体   中英

Get first letter from string in php and insert a html command

I try to get first character from string and insert a html command for it.

<?php
    $str = nl2br($personal_data['about']);
    if $str[0] {
?>
    <span class="dropcap">
<?php }  echo $str[0] ?>

I try something like that, but don't works.

Please, give me another idea for do that.

Thanks for help!

You can use the function substr() for get the letters you want.

substr ( $YourString, Int StartLetter, Int NumberLetter)

So for you that will be like this.

$str = substr ( $personal_data['about'] , 0 , 1 )

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM