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

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




Only adding a certain number of characters to a variable

 
Reply to this topicStart new topic

Only adding a certain number of characters to a variable

BetaWar
19 Sep, 2006 - 05:45 PM
Post #1

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,054



Thanked: 84 times
Dream Kudos: 1175
My Contributions
Okay I am attempting to redo my site for the moment and would like to have a description section on my news articles instead of having them each show the whole story. I have inserted a description place int eh mysql database however am having trouble comming up with a script that will copy a variable to a certain length to another variable. I want something like a function which would work great.

Something like this:

CODE

$testString='This is a test string of 39 characters.';
$testString2='';

//Set $testString2 to the value of testString but only upto character 10

$testString2='This is a ';


I have only found ways to count the number of characters in a variable at this point, but would liek to be able to set a certain number of characters allowed into a variable. Hopefully someone will be able to help.

THanks,
BetaWar
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Only Adding A Certain Number Of Characters To A Variable
19 Sep, 2006 - 05:50 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
CODE

$testString2=substr($testString,0,10);
echo $testString2;

should do the trick.

http://ca3.php.net/strings
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Only Adding A Certain Number Of Characters To A Variable
19 Sep, 2006 - 05:54 PM
Post #3

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,054



Thanked: 84 times
Dream Kudos: 1175
My Contributions
Wow, thansk man. It works. I know simple thing, but I am a pretty big noob to PHP (started over the summer...)
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Only Adding A Certain Number Of Characters To A Variable
23 Dec, 2006 - 08:44 PM
Post #4

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,054



Thanked: 84 times
Dream Kudos: 1175
My Contributions
Sorry to dig up this old topic, however now I need something that will take the character limit (as before) but leave the HTML tags in tact, so somethimg that goes through and rips the HTML tags out then adds tem back in after creating a story description.
User is offlineProfile CardPM
+Quote Post

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

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