Welcome to Dream.In.Code
Become a PHP Expert!

Join 137,424 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,946 people online right now. Registration is fast and FREE... Join Now!




Function Help

 
Reply to this topicStart new topic

Function Help, I need some resources on special functions

supersssweety
12 Jan, 2008 - 06:14 AM
Post #1

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 312


Dream Kudos: 125
My Contributions
Fuction 1:

Is there a function that will help me count characters in a variable

Function 2:

Is there a function that will truncate the characters in the variable if there is more than 100 characters

I tested count_chars and ftruncate but got these error:

Warning: count_chars() [function.count-chars]: Unknown mode. in /home/kacieh/public_html/index.php on line 7

Warning: ftruncate(): supplied argument is not a valid stream resource in /home/kacieh/public_html/index.php on line 8

CODE

$var = "This is a really long string I want to see if I can truncate this string to being only 10 chars long, let's hope it works";
$size = 10;
echo count_chars($var, 10);
echo ftruncate($var, $size);


I don't know what that means
I really don't care why these didn't work unless somehow they will work and I am just doing something wrong, if they won't work, what will?
User is offlineProfile CardPM
+Quote Post

MitkOK
RE: Function Help
12 Jan, 2008 - 06:23 AM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 314



Thanked: 12 times
Dream Kudos: 250
My Contributions
For counting characters - http://bg2.php.net/strlen

You can cut string using substr - http://bg2.php.net/manual/en/function.substr.php

This post has been edited by MitkOK: 12 Jan, 2008 - 06:28 AM
User is offlineProfile CardPM
+Quote Post

supersssweety
RE: Function Help
12 Jan, 2008 - 06:24 AM
Post #3

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 312


Dream Kudos: 125
My Contributions
Thanks man
User is offlineProfile CardPM
+Quote Post

supersssweety
RE: Function Help
12 Jan, 2008 - 07:02 AM
Post #4

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 312


Dream Kudos: 125
My Contributions
So I got it figured out:

CODE

if (true === (strlen($value) > 100))
{
    $value = substr($value, 0, 100)
}


QUOTE(MitkOK @ 12 Jan, 2008 - 07:23 AM) *

For counting characters - http://bg2.php.net/strlen

You can cut string using substr - http://bg2.php.net/manual/en/function.substr.php

oh you edited it I didn't see that, but one of the other devs came in and pointed that one out to me, thanks though
User is offlineProfile CardPM
+Quote Post

MitkOK
RE: Function Help
12 Jan, 2008 - 07:13 AM
Post #5

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 314



Thanked: 12 times
Dream Kudos: 250
My Contributions
You can skip if ( true == ) and write it just like that :
CODE
if (strlen($value) > 100)
{
    $value = substr($value, 0, 100)
}

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 04:36AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month