2 Questions

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

2 Questions

Corey
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
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
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
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
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
Sorry, I was thinking about a single function to extract a set of characters rather than a series concatenated together.

Reply

Corey
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
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



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : questions

  1. 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. ...
  2. Questions?! - PHP (4)
  3. 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...
  4. 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...
  5. 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' /> ...
  6. 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. ...
  7. 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...
  8. 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

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for 2, questions

*MORE FROM TRAP17.COM*
advertisement



2 Questions



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE