Corey
May 29 2005, 05:39 PM
| | i have 2 questions about PHP...please don't answer like "use google"...or something...because i tried and didn't find anything..so
1.
example..i have a varible called $var and it contains 50 characters..so how can i write only part of them (1,2,3,20)?
2.
example like the one before... i have a varible called $var with 50 characters..how can i write the first /second /third.. charachter from the $var
tnx;) |
Reply
OpaQue
May 29 2005, 06:05 PM
The substr function of PHP will allow you to get part of the variable. The access particular characters, you will have to use a Curly braces. Suppose, you have $var="tommy"; So, $var{1} will give you "o" as output. This is a rough idea since I haven't used this function for a long time. However, you can search for substr directly now :-) instead of searching everything.
Reply
Tyssen
May 30 2005, 12:08 AM
You can also specify the number of characters and count from the begining or end of the string. PHP.net has some good examples of how that works. But I think you can only use substr if the characters run in succession, e.g. 1-3, 4-8 etc. If you want to extract characters at random e.g. 1,3,7,9,12, you might have to create an array of different characters and work with that instead.
Reply
OpaQue
May 30 2005, 12:16 AM
An Array of diffrent characters is not needed. Strings are stored as arrays internally. All you have to do is access the diffrent characters using the following syntax, $variable_name{index}; index will be the character postion from 0. Try it out :-).
Reply
Mike
May 30 2005, 12:43 AM
Like OpaQue said, you would use the substr() function. The only thing that I am not sure about in what OpaQue posted, is the $variable{n}. Unless that is another way to use the substr function, quickly of course. Basically the substr() function works like substr($variable, nlettertostartat); CODE <?php
$string = 'Testing'; $substr = substr($string,3);
echo $substr; // Result: 'ting'
?>
Actually, if you want to just get a certain character/characters, do what OpaQue said. $variable{n characetr [1,2,3,4,etc]}.
Reply
Tyssen
May 30 2005, 01:36 AM
Sorry, I was thinking about a single function to extract a set of characters rather than a series concatenated together.
Reply
Corey
May 30 2005, 08:01 AM
tnx everyone .. btw.. do you know some simple script that can write the content of some folder.. example - Downloads -1.rar -3.rar -5.jpg ...
Reply
Tyssen
May 30 2005, 12:03 PM
Here's a stripped down version of one I use on a site I'm developing for a friend: CODE if ($handle = opendir($PathtoYourDirectory)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $file_array[] = $file; } } } closedir($handle); $result=array_unique($file_array); natcasesort($result); reset($file_array); foreach($result as $file){ echo $file."<br />"; } unset($file_array);
Reply
Similar Topics
Keywords : questions- Wap Forum
- several questions on WAP forums (9)
/blink.gif' border='0' style='vertical-align:middle' alt='blink.gif' /> Right i want to set up a
wap forum for rap battling. I think i need to use php, although i might need wml not sure. so
questions: 1) WML or PHP? 2) Can i get a forum/message board script? 3) Where can i get it? Thanks
in advance Not making helpful thread topics and titles results in warnings, or in extreme cases, a
ban. Don't fall into the crack. ...
Questions?!
- PHP (4)
Php Questions?!
- From: alex1985 (19)
Listen, as I'm novice in PHP, I will ask certain questions in this topic hoping on your
contribution. $dbhost='.....'; //The Database Information//
$dbhost='localhost'; $dbname='alex1985_test';
$dbusername='alex1985_admin'; $dbuserpass='0505009127'; //Creating
Connection To The Database// mysql_connect ($dbhost, $dbusername, $dbuserpass);
//Select The Certain Database// mysql_select_db ($dbname) or die ('Can Not Select
Database'); //Start The Session// //Always Must...
Gd Functions
- Questions (2)
Hi all I want begin a new project , my new project is Photo blog ( weblog and image album ) in one
script for example you can post many image in one post at once case . so its very good and very easy
but we have some problems . if you can plz help me to fix this problems for example : we need
change image size for page speed ( we dont want show 16 image in one page ) * we need GD functions
to change image size to smaller and then show smaller image at page if you know source or tutorial
about change image size plz post here . thankx we know we can change image size (w...
Javascript To Php - A Few Questions
- (1)
I am rewriting a Javascript into PHP, but I have two questions: How can I write these functions in
PHP? Math.floor Math.ceil I'm sure the answer is obvious, but I really can't find it...
/laugh.gif' border='0' style='vertical-align:middle' alt='laugh.gif' /> ...
A Lot Of Php Questions Part 2
- (8)
Ok, here's another. After looking at many PHP codes, I will call it "PHP Shortcuts". Do you
still know any other "PHP Shortcuts"? Example, to "print" the visitor's IP address, I use CODE
<html><head></head><body><?php print
$_SERVER['REMOTE_ADDR']; ?></body></html> After seeing
someone's codes, I saw an easy way CODE
<?=$_SERVER['REMOTE_ADDR'];?> So, you know any more of that? And for
MySQL, I know there are many ways to retrieve the results. ...
A Lot Of Php Questions
- please do help me (3)
First , i'm planning to use preg_match, ereg_match, etc.. I think "preg" and "ereg" uses
something like in the Apache's RewriteModule the " " something like that... Do you know a
tutorial that will easily teach me on how to do that? Second , I'm planning to use Apache
Rewrite. But I really don't know how to use. Do you know a tutorial that will easily teach me on
how to do that? Third , while openning some php scripts, I didn't get the meaning of example:
CODE <?php $sample1->//some string here ?> What does it mean? I di...
Html To Php Questions
- (3)
Hi, I would like to know if it is safe to change HTML files to PHP files by just changing the
dotHTML extension to dotPHP?? I tried it to a single html file because i used a php code of blog,
and it worked. I'm using Internet Explore version 6 and it's working fine. I would like to
know if the PHp files would work for other browsers after changing dotHTML to dotPHP extension.
Thanks...
Looking for 2, questions
|
|
Searching Video's for 2, questions
|
advertisement
|
|