Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> 2 Questions
Corey
post May 29 2005, 05:39 PM
Post #1


Super Member
*********

Group: Members
Posts: 218
Joined: 13-January 05
Member No.: 3,267



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;)
Go to the top of the page
 
+Quote Post
OpaQue
post May 29 2005, 06:05 PM
Post #2


Administrator
Group Icon

Group: Admin
Posts: 1,459
Joined: 11-June 04
From: Somewhere in Time & Space.
Member No.: 1



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.
Go to the top of the page
 
+Quote Post
Tyssen
post May 30 2005, 12:08 AM
Post #3



***********

Group: Members
Posts: 1,161
Joined: 9-May 05
From: Brisbane, QLD
Member No.: 6,818



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.
Go to the top of the page
 
+Quote Post
OpaQue
post May 30 2005, 12:16 AM
Post #4


Administrator
Group Icon

Group: Admin
Posts: 1,459
Joined: 11-June 04
From: Somewhere in Time & Space.
Member No.: 1



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 :-).
Go to the top of the page
 
+Quote Post
Mike
post May 30 2005, 12:43 AM
Post #5


Owner of Sub-Zero
********

Group: Members
Posts: 159
Joined: 17-November 04
Member No.: 2,325



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]}.
Go to the top of the page
 
+Quote Post
Tyssen
post May 30 2005, 01:36 AM
Post #6



***********

Group: Members
Posts: 1,161
Joined: 9-May 05
From: Brisbane, QLD
Member No.: 6,818



Sorry, I was thinking about a single function to extract a set of characters rather than a series concatenated together.
Go to the top of the page
 
+Quote Post
Corey
post May 30 2005, 08:01 AM
Post #7


Super Member
*********

Group: Members
Posts: 218
Joined: 13-January 05
Member No.: 3,267



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

...
Go to the top of the page
 
+Quote Post
Tyssen
post May 30 2005, 12:03 PM
Post #8



***********

Group: Members
Posts: 1,161
Joined: 9-May 05
From: Brisbane, QLD
Member No.: 6,818



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);
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Some Questions On Html(6)
  2. Dog Questions(26)
  3. Rpg Maker 2003 Questions(29)
  4. Warped Tour!(0)
  5. Questions About The Budget Freedom Plan(4)
  6. Meta Tags(7)
  7. Difference Between C, C++ And C#?(15)
  8. Some Of The Biggest Questions In Life.(3)
  9. Dell D600 Questions(2)
  10. Allie's Advice(5)
  11. A Couple Of Questions About Delphi(3)
  12. Tax Deduction Questions...(0)
  13. Some Questions About Qupis Hosting !(2)
  14. Webdesign Frequently Askd Questions(11)
  15. I Have Several Random Questions...(8)
  1. Finance Section Suggested(0)
  2. Some American Football Questions(6)
  3. Document.write & Noscript Questions (javascript)(1)
  4. Wap Forum(9)
  5. Questions?!(4)
  6. What's The Problem With America's Youth?(69)
  7. Joomla Noob Questions(4)
  8. Flash And Javascript Interaction(1)
  9. Php Questions?!(19)
  10. Questions About Upgrading A Freedom Package(0)
  11. Group Limitations(0)
  12. Dreamweaver Mx 2004: A Q&a Topic By Sean Mallon(5)
  13. Rpg Maker 2003 Questions(2)
  14. Legal Disclaimer Questions(1)
  15. Copyright Questions(10)