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
https://forums.phpfreaks.com/topic/212592-php-setting-limit-to-html-text-output/
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.

I'm just too stupid to implement it i think  :(

 

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

 

This does not change anything, i changed it to 4 to see if it does anything atleast, but it does not ):

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.