SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: php Function

  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php Function

    Hi,

    I have a function in my script and this will take the parameter from the url to give an output. The output has almost 10 variables($age, $name....). I want to use this function in my other files(php) but I do not want to print all the output(10). Depending on the page I am I want to display 2 out 10 or 3 out of 10 variables. I am sure its possible but not sure how to get it.

    For example,
    <?php
    Function show_data($id) {

    $link = "http://abc.com?id=$_GET['id']";

    //I will do fopen($link,r) and then get the data stored from the link.
    //After doing some text manipulation like adding uppercase, removing "" etc I will have the output stored as
    $name= $data[0];
    $age= $data[2];
    //etc..
    //then close the function
    ?>

    So I want to use this function to just display the required output based on the place/page where I want to, something like this :
    //Call the above function and then just show age in file_one.php
    //Call the above function and then just show name in file_two.php


    Please help me out and let me know if I am clear in explaining this.

    thanks
    pragan.

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the future please use [code] or [php] tags to make your post easier to read.

    This should help:

    PHP Code:
    <?php

    function showData()
    {
        
    $args func_get_args();

        
    $id array_shift($args);

        
    $name 'Joe Blow';
        
    $age  21;
        
    $foo  'bazbazbaz';

        foreach (
    $args as $arg) {
            echo ${
    $arg} . "\n";
        }
    }

    /**
     * Output:
     * Joe Blow
     * 21
     */
    showData('SomeId''name''age'); 

    /**
     * Output:
     * Joe Blow
     * bazbazbaz 
     */
    showData('SomeId''name''foo');

    /**
     * Output:
     * 21
     * Joe Blow
     * bazbazbaz 
     * bazbazbaz 
     */
    showData('SomeId''age''name''foo''foo');
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the help. Your idea helped me in writing my code.thanks again.
    Sure, I will put the code inside the code tag.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •