/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] substr parameter count

Hi, I am trying to split a string of text and break it in to two lines if it is longer than the space I have.

Here is the code I have;

[code=php]
$text = (substr(stripslashes($spot[‘description’]),0, 22). “<br />”.substr(stripslashes($spot[‘description’]),23, 40));
if(substr(stripslashes($spot[‘description’])) > 40){ $text = $text .”…”; }[/code]

But am getting this error

[code]Warning: Wrong parameter count for substr() in /home/httpd/vhosts/ziplinestaging.com/httpdocs/spokesmaniframe/iframe.php on line 110[/code]

Yet it matched the examples on PHP.net
[url]http://us.php.net/substr[/url]

[code=php]<?php
$rest = substr(“abcdef”, 0, -1); // returns “abcde”
$rest = substr(“abcdef”, 2, -1); // returns “cde”
$rest = substr(“abcdef”, 4, -4); // returns “”
$rest = substr(“abcdef”, -3, -1); // returns “de”
?> [/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 06.2007 — You only gave it one parameter in this expression (the string returned by stripslahses). substr() requires at least the 2nd parameter for the starting index.
[code=php]
if(substr(stripslashes($spot['description'])) > 40)
[/code]
Copy linkTweet thisAlerts:
@SheldonauthorSep 06.2007 — Ah of course!

Thanks, i should be using [url=http://us.php.net/strlen]strlen[/url].
×

Success!

Help @Sheldon 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...