Jump to content

PHP: Setting Limit to html text output?


danny44

Recommended Posts

Hello! Im new here and want to start my new php carreer  ;D

Well, I'm already working quite hard, but now I don't know what to do

 

I've got it so far:

 

<?php echo html::chars($message->text); ?>

 

Is there any way I could modify the output, so it just displays the first 20 characters or so?

 

 

Thank you all very much!

Link to comment
Share on other sites

So you're wanting the leading line for a block of text?

Similiar to use in forums ect...

 

You could use the following to stop at 20 characters outputted

$leadingLine = trim(substr($YourTextString,0,20));

 

Try the above, and tell me how it goes.

 

Regards, Paul.

Link to comment
Share on other sites

Ohh right, what text does "html::chars($message->text)" contain?

 

Try this, i'm not 100% sure if it will work but it's worth a go?

$leadingLine = trim(substr(html::chars($message->text),0,4));

 

Then when calling the text use

<?PHP echo $leadingLine;?>

 

or something like that, depending on your situation.

 

Thanks, Paul.

Link to comment
Share on other sites

Thank you very much Paul, it works!    ;)

Took me some time, but hey, I have to start somewhere  :shy:... it's working now!

 

Is there any way to add a specified text after the text, if it gets cutted?

 

For example if the text gets cutted, he adds "read on" to the text:

In this article I tell you someth read on

 

 

Maybe there is some easy way to do this

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.