/    Sign up×
Community /Pin to ProfileBookmark

Php–HTML issue

Hi friends

I have stored in my table more then 100 characters. but i want to retrieve only 40 characters and display the message only 4 lines ,–each line get in 10 characters only .
Please give me some idea for this task

Thanks
vssp

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@GenixdeaeJul 24.2006 — [URL=http://us3.php.net/substr]substr()[/URL] - [code=php]$text = "all your text here";
echo substr($text, 0, 20) ."<br>";
echo substr($text, 20, 40) ."<br>";
echo substr($text, 40, 60) ."<br>";
echo substr($text, 60, 80);[/code]
Just an idea, hope it helps
Copy linkTweet thisAlerts:
@vsspauthorJul 24.2006 — Thanks Genixdeae........

Sorry , I need another clarification how to split the words.

I have stored in my table more then 100 words but i want to retrieve only 40 words and display the message only 4 lines ,--each line get in 10 words only .

Please give me some idea for this task




Thanks

Vssp
Copy linkTweet thisAlerts:
@shane_carrJul 24.2006 — Same code, but (you mean mysql table???) you should change the params to

0,10

10,20

20,30

30,40

And also, I tend to prefer <br /> rather than <br>. That's just a personal preference.
Copy linkTweet thisAlerts:
@GenixdeaeJul 24.2006 — [URL=http://us3.php.net/explode]explode()[/URL] You'll have to mess with this on your own, i'm hazy on explode and it's abilities [code=php]$text = "your text";
explode(" ", $text);[/code]


ps:shane, i did it <br> because it's midnight and i'm tired and lazy :p , but i usually do <br /> also
Copy linkTweet thisAlerts:
@vsspauthorJul 24.2006 — Thanks for your replay ,Yes mysql table shane.carr ..

Thansk for your help Genixdeae .Good nite have nice day.

Thanks

Vssp
Copy linkTweet thisAlerts:
@shane_carrJul 24.2006 — Why didn't I think of that before?

[code=php]
$var1 = mysql_query("your query");
//more mysql stuff
$var2 = "final text";

$var3 = explode(" ", $var2);
$var4 = "";

$i = 0;
while($i<40){
$var4 .= $var3[$i]." ";
$i++
if($i==(10||20||30)){
$var4 .= "<br />";
}
}

echo $var4;[/code]
Copy linkTweet thisAlerts:
@vsspauthorJul 24.2006 — Thanks shane.carr

Thanks for your help Its very usefill for me.

VSSP ?
Copy linkTweet thisAlerts:
@shane_carrJul 24.2006 — So we're finished? Great ? Unless you figured it out yourself, the if was always evaluating true. Change it to:

[code=php]
if($i==10||$i==20||$i==30){
[/code]


and it should work even better. Cheers!
Copy linkTweet thisAlerts:
@Vectorman211Jul 24.2006 — may want to do:

[code=php]
preg_split("/ +/",$text);
[/code]


Instead which will match any number of spaces (just in case).
Copy linkTweet thisAlerts:
@shane_carrJul 24.2006 — may want to do:

[code=php]
preg_split("/ +/",$text);
[/code]


Instead which will match any number of spaces (just in case).[/QUOTE]

That's probably a good idea. That'll make the code

[code=php]
$var1 = mysql_query("your query");
//more mysql stuff
$var2 = "final text";

$var3 = preg_split("/ +/",$var2);
$var4 = "";

$i = 0;
while($i<40){
$var4 .= $var3[$i]." ";
$i++
if($i==10||$i==20||$i==30){
$var4 .= "<br />";
}
}

echo $var4;[/code]
×

Success!

Help @vssp 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 11.28,
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: @bahaedd,
tipped: article
amount: 1000 SATS,

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

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