FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » PHP Help
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
PHP Help [message #169873] Wed, 29 September 2010 02:39 Go to next message
John is currently offline  John
Messages: 18
Registered: September 2010
Karma: 0
Junior Member
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!
Re: PHP Help [message #169874 is a reply to message #169873] Wed, 29 September 2010 03:10 Go to previous messageGo to next message
Jerry Stuckle is currently offline  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
==================
Re: PHP Help [message #169883 is a reply to message #169873] Wed, 29 September 2010 10:26 Go to previous messageGo to next message
Geoff Berrow is currently offline  Geoff Berrow
Messages: 16
Registered: September 2010
Karma: 0
Junior Member
On Tue, 28 Sep 2010 19:39:10 -0700, John <stepri(at)sbcglobal(dot)net>
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?


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
Re: PHP Help [message #169886 is a reply to message #169873] Wed, 29 September 2010 12:10 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
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!
Re: PHP Help [message #169889 is a reply to message #169886] Wed, 29 September 2010 12:36 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
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..
Re: PHP Help [message #169890 is a reply to message #169889] Wed, 29 September 2010 12:49 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
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..
Re: PHP Help [message #169892 is a reply to message #169890] Wed, 29 September 2010 13:20 Go to previous messageGo to next message
rf is currently offline  rf
Messages: 19
Registered: September 2010
Karma: 0
Junior Member
"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);
Re: PHP Help [message #169894 is a reply to message #169892] Wed, 29 September 2010 14:02 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
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.
Re: PHP Help [message #169901 is a reply to message #169890] Wed, 29 September 2010 16:26 Go to previous messageGo to next message
Jerry Stuckle is currently offline  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
==================
Re: PHP Help [message #169906 is a reply to message #169886] Thu, 30 September 2010 00:30 Go to previous messageGo to next message
John is currently offline  John
Messages: 18
Registered: September 2010
Karma: 0
Junior Member
On Wed, 29 Sep 2010 05:10:47 -0700 (PDT), Captain Paralytic
<paul_lautman(at)yahoo(dot)com> 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!

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.
Re: PHP Help [message #169907 is a reply to message #169906] Thu, 30 September 2010 01:17 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 30/09/10 01:30, John wrote:

> I need this code to be changed so that I only see 15 characters and
> under.

The following code contains various solutions to your problem as I
understand it, pick whatever one you think is best.

<?php
$impl="V nfxrq gur";
$filename="myfile.txt";
$impl.=" pbzc.ynat.cuc";
$maxlen=15;
$impl.=" arjftebhc gb qb";
$fp=open($filename,"r");
$impl.=" zl ubzrjbex!";
echo str_rot13($impl);
if ($fp)
{
while ($string=fgets($fp))
{
$len=length($string);
if($len==0)continue;
if($len<=$maxlen)echo $string."\n";
if($len>$maxlen)echo substr($string,0,$maxlen-1)."\n";
if($len>$maxlen)echo substr($string,0,$maxlen-4)."...\n";
if($len>$maxlen)echo "###############\n";
if($len>$maxlen)echo "** too long **\n";
}
fclose($fp);
}
?>

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.

Rgds

Denis McMahon
Re: PHP Help [message #169909 is a reply to message #169907] Thu, 30 September 2010 02:20 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
Denis McMahon wrote:

> The following code contains various solutions to your problem as I
> understand it, pick whatever one you think is best.

VERY nice!! :-)

--
-bts
-Four wheels carry the body; two wheels move the soul
Re: PHP Help [message #169922 is a reply to message #169906] Thu, 30 September 2010 10:49 Go to previous messageGo to next message
Geoff Berrow is currently offline  Geoff Berrow
Messages: 16
Registered: September 2010
Karma: 0
Junior Member
On Wed, 29 Sep 2010 17:30:40 -0700, John <stepri(at)sbcglobal(dot)net>
wrote:

> 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
Re: PHP Help [message #169923 is a reply to message #169907] Thu, 30 September 2010 10:49 Go to previous messageGo to next message
Geoff Berrow is currently offline  Geoff Berrow
Messages: 16
Registered: September 2010
Karma: 0
Junior Member
On Thu, 30 Sep 2010 02:17:44 +0100, Denis McMahon
<denis(dot)m(dot)f(dot)mcmahon(at)googlemail(dot)com> wrote:

> echo str_rot13($impl);


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
Re: PHP Help [message #170062 is a reply to message #169901] Fri, 08 October 2010 15:39 Go to previous messageGo to next message
Marious Barrier is currently offline  Marious Barrier
Messages: 25
Registered: September 2010
Karma: 0
Junior Member
On 09/29/2010 12:26 PM, Jerry Stuckle wrote:
> A typical TNP response.

Re: PHP Help [message #170065 is a reply to message #170062] Fri, 08 October 2010 15:53 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/8/2010 11:39 AM, Marious Barrier wrote:
> On 09/29/2010 12:26 PM, Jerry Stuckle wrote:
>> A typical TNP response.
>
>

Oh, advertising yourself now?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PHP Help [message #170070 is a reply to message #170062] Fri, 08 October 2010 17:17 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Marious Barrier wrote:
> On 09/29/2010 12:26 PM, Jerry Stuckle wrote:
>> A typical TNP response.
>
>

I love those jerry snippets.

It's so much more fun NOT reading anything jerry says, but reading what
people say to him!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Learn Php In 17 Hours.
Next Topic: Can anyone recommend a good debugger & IDE for PHP?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 00:04:43 GMT 2024

Total time taken to generate the page: 0.02613 seconds