/    Sign up×
Community /Pin to ProfileBookmark

Special things with Strings

Hey everyone! I just want to know if it is possible to get a certain character in a string, say the 3rd or 67th character. Also, how do you get the length of a string?

Thanks in advance for any replies!

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@bokehAug 14.2005 — Position:
[code=php]$sub = substr($string, $position, $length)
3rd char: $sub = substr($string, 2, 1);
67th char $sub = substr($string, 66, 1);[/code]


length:
[code=php]$length = strlen($string);[/code]
Copy linkTweet thisAlerts:
@NogDogAug 14.2005 — An alternative way to refer to a specific character in a string is...
[code=php]
$string = "123456789";
$letter_nbr_5 = $string{4}; # numbering starts at 0
[/code]
Copy linkTweet thisAlerts:
@aznchong91authorAug 14.2005 — Thanks guys! Really appreciate it!
Copy linkTweet thisAlerts:
@aznchong91authorAug 14.2005 — Just as an extra reference...How do you generate random numbers again? Just integers please...
Copy linkTweet thisAlerts:
@bokehAug 14.2005 — Random number between '0' and '1000':
[code=php]$random_number = rand(0, 1000);[/code]
Copy linkTweet thisAlerts:
@aznchong91authorAug 15.2005 — Thanks.
Copy linkTweet thisAlerts:
@ShrineDesignsAug 15.2005 — [i]int[/i] [b]mt_rand[/b]([i]int[/i] min, [i]int[/i] max)
×

Success!

Help @aznchong91 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...