Jerry Stuckle Messages: 2598 Registered: September 2010
Karma: 0
Senior Member
On 9/28/2010 10:39 PM, John wrote:
> I have a script that pulls a .txt file and displays the results for
> me.
>
> I need the scipt to limit the number of letters to not more than 15
> letters, but not 15 letters exactly.
>
> Can someone show me a code example on how to do this please?
>
> Thanks!
What have you tried so far?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex(at)attglobal(dot)net
==================
> I have a script that pulls a .txt file and displays the results for
> me.
>
> I need the scipt to limit the number of letters to not more than 15
> letters, but not 15 letters exactly.
>
> Can someone show me a code example on how to do this please?
http://lmgtfy.com/?q=php+string+length
--
Geoff Berrow (Put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs www.4theweb.co.uk/rfdmaker
Captain Paralytic wrote:
> On 29 Sep, 03:39, John <ste...@sbcglobal.net> wrote:
>> I have a script that pulls a .txt file and displays the results for
>> me.
>
> What is the input? What are these "results"?
>
>> I need the scipt to limit the number of letters to not more than 15
>> letters, but not 15 letters exactly.
>
> This makes no sense at all. Please think about what it is you actually
> want and supply an example!
The Natural Philosopher wrote:
> Captain Paralytic wrote:
>> On 29 Sep, 03:39, John <ste...@sbcglobal.net> wrote:
>>> I have a script that pulls a .txt file and displays the results for
>>> me.
>>
>> What is the input? What are these "results"?
>>
>>> I need the scipt to limit the number of letters to not more than 15
>>> letters, but not 15 letters exactly.
>>
>> This makes no sense at all. Please think about what it is you actually
>> want and supply an example!
>
> sounds like a calassic truncation exercise.
>
> If lenth>15
> then truncate to 15..
>
"The Natural Philosopher" <tnp(at)invalid(dot)invalid> wrote in message
news:i7vcki$cqf$3(at)news(dot)albasani(dot)net...
> The Natural Philosopher wrote:
>> Captain Paralytic wrote:
>>> On 29 Sep, 03:39, John <ste...@sbcglobal.net> wrote:
>>>> I have a script that pulls a .txt file and displays the results for
>>>> me.
>>>
>>> What is the input? What are these "results"?
>>>
>>>> I need the scipt to limit the number of letters to not more than 15
>>>> letters, but not 15 letters exactly.
>>>
>>> This makes no sense at all. Please think about what it is you actually
>>> want and supply an example!
>>
>> sounds like a calassic truncation exercise.
>>
>> If lenth>15
>> then truncate to 15..
>>
>
> $trimmed=sprintf("%15s",$original);
>
> should do it, but I am rusty on printf..
rf wrote:
> "The Natural Philosopher" <tnp(at)invalid(dot)invalid> wrote in message
> news:i7vcki$cqf$3(at)news(dot)albasani(dot)net...
>> The Natural Philosopher wrote:
>>> Captain Paralytic wrote:
>>>> On 29 Sep, 03:39, John <ste...@sbcglobal.net> wrote:
>>>> > I have a script that pulls a .txt file and displays the results for
>>>> > me.
>>>> What is the input? What are these "results"?
>>>>
>>>> > I need the scipt to limit the number of letters to not more than 15
>>>> > letters, but not 15 letters exactly.
>>>> This makes no sense at all. Please think about what it is you actually
>>>> want and supply an example!
>>> sounds like a calassic truncation exercise.
>>>
>>> If lenth>15
>>> then truncate to 15..
>>>
>> $trimmed=sprintf("%15s",$original);
>>
>> should do it, but I am rusty on printf..
>
> Overkill.
>
> $trimmed = substr($original,0,15);
>
>
even better.
Jerry Stuckle Messages: 2598 Registered: September 2010
Karma: 0
Senior Member
On 9/29/2010 8:49 AM, The Natural Philosopher wrote:
> The Natural Philosopher wrote:
>> Captain Paralytic wrote:
>>> On 29 Sep, 03:39, John <ste...@sbcglobal.net> wrote:
>>>> I have a script that pulls a .txt file and displays the results for
>>>> me.
>>>
>>> What is the input? What are these "results"?
>>>
>>>> I need the scipt to limit the number of letters to not more than 15
>>>> letters, but not 15 letters exactly.
>>>
>>> This makes no sense at all. Please think about what it is you actually
>>> want and supply an example!
>>
>> sounds like a calassic truncation exercise.
>>
>> If lenth>15
>> then truncate to 15..
>>
>
> $trimmed=sprintf("%15s",$original);
>
> should do it, but I am rusty on printf..
Which doesn't work, because the %15 is the minimum length of the string
- not the maximum.
A typical TNP response.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. jstucklex(at)attglobal(dot)net
==================
> On 29 Sep, 03:39, John <ste...@sbcglobal.net> wrote:
>> I have a script that pulls a .txt file and displays the results for
>> me.
>
> What is the input? What are these "results"?
>
>> I need the scipt to limit the number of letters to not more than 15
>> letters, but not 15 letters exactly.
>
> This makes no sense at all. Please think about what it is you actually
> want and supply an example!
Here is the line that I need to work:
$length = (strlen($length) > 0) ? $length : null;
I need this code to be changed so that I only see 15 characters and
under.
Either I have completely misunderstood your requirement, in which case
you need to explain what your problem is in more detail, or the above
should help you on the path which you seek.
> Here is the line that I need to work:
>
> $length = (strlen($length) > 0) ? $length : null;
>
> I need this code to be changed so that I only see 15 characters and
> under.
I give up...
<?php
$string="Your line of text that is more than 15 chars long";
$string= substr($string, 0, 15);
echo $string;
?>
I highly recommend browsing through the functions in the manual.
--
Geoff Berrow (Put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs www.4theweb.co.uk/rfdmaker
heh...
--
Geoff Berrow (Put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs www.4theweb.co.uk/rfdmaker