Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Arrays, Functions


I know this has been covered, because I've been reading everything I can on the subject, but I can't seem to figure out how to pass arrays into and out of my functions. PHP Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Passing Arrays To Functions
[code]
$job_status = array(
"unassigned",
"current",
"completed"
);

function gimme($name){
echo $$name; // this is in hopes to echo the contents of $job_status when gimme(job_status) is called
}

How can I get $name to be the ARRAY $job_status? I'm trying to keep this very modular so that I can also perform:

gimme(job_type); among others.

Question About Arrays And Functions
$sql = "DELETE FROM " . $mosConfig_dbprefix . "foo WHERE foo_id = '" .
mosGetParam($_POST, 'cid', '' )[$a] . "'";

was throwing errors and I fixed it be doing this:

$cidx = mosGetParam( $_POST, 'cid', '' );
$sql = "DELETE FROM " . $mosConfig_dbprefix . "foo WHERE foo_id = '" .
$cidx[$a] . "'";

My question is why didn't the first version work and is there a way to
code it without adding the intermediate variable?

Passing Arrays To Functions
How do I pass an array to a function? This is what I have, and the second
function doesn't seem to be getting the array somehow. I'm sure it's in
the function declaration...

function one(){
return $array; // yes, there is more to this function, and assume that
"$array" is a real array
}

funtcion two($arrayArg){ // <- I'm sure the prob is here.
print_r($arrayArg); // This isn't printing anything, when it does in one()
}

then I call:
two(one());

Once again, I'm sure the prob is in the declaration.

Arrays And While Mysql Functions
How can I get this array to work? I am trying to add data to an array for every row of data? This is a sellection of queries that I need to parse into an array so a function can use the arra to draw a graph. I am new to arrays how can I get this to work? Code:

Elements From Functions That Return Arrays
I'd like to access a single element from a function that returns an
array; and I'd like to do it in a single statement.

Here's an example. This is obvious.
$a = explode(".", "this.is.some.text");
$b = $a[2];

So how can I do that in a single statement?
$a = explode(".", "this.is.some.text")[2] // no
$a = (explode(".", "this.is.some.text"))[2] // nope
$a = [explode(".", "this.is.some.text")][2] // no way

How close am I coming to the final result. My goal is to be able to
nest them.

I was looking for an answer in the array functions, but the ones I
found don't return a scalar value, they return arrays in my cases.

How Do You Pass Functions Via Arrays Into Loops?
How do I pass a function through an array into a loop? I'll explain what I mean. I have a function (do_telcos) which just grabs a list of Telephone companies and their IDs and spits them into a dropdown box. I'm trying to use this in a form that I'm building from an array as follows: Code:

DBM Functions:: Undefined Functions Error
I have been trying to use the DBM Functions (dbmopen etc) in php but always get an undefined funtion error. Do I need to load something or change something in the .ini file to get it to work?

thanks
MIke

Arrays Within Arrays, How To Split
I have been stumped on this one and it is probably easier than I think it is, especially since my brain is fried.

This is what my array looks like:
array(7) { ["injuredPerson"]=> string(0) "" ["dates"]=> string(0) "" ["describe"]=> string(0) "" ["location"]=> string(0) "" ["type"]=> array(3) { [0]=> string(8) "abrasion" [1]=> string(10) "amputation" [2]=> string(12) "asphyxiation" } ["part"]=> string(0) "" ["times"]=> string(0) "" }

This is actually an array of information from a form check. I have the error handling check the form and depending on if there is an error or not, the array gets populated with "" or an actual value(s).

I am testing a checkbox area of the form (the name is type, so type can hold an array of values, thats why it currently contains abrasion, amputation, and asphyxiation).

I have had no problem going through the array until I get to the area with an array within the array. Let me give you some code so you can see how I am doing this:

Searching Arrays With Arrays
ive looked through alot of the array search functions and i dont think any of them support arrays as the "needle" to search for.

so say i had a numeric array, $array1 with say 5 elements, 0-4, each element is a single word, lowercase.

say i had another numeric array structured the same way called $array2 with say about 5 elements, 0-4. Is there a function which i could use or does anyone know of an easy way to search every element in $array1 and compair it through each of the elements of $array2? and if a duplicate is found in $array2 have that element be removed or unset? im sure this can be done probably easy with some kind of loop function, but thats my weak point right now in php and im working on it.

Do We Need This Functions?
I'd like to check with others what are the least used functions in PHP, since I think that it is becoming more and more filled with unuseful addons while missing useful extensions like SOAP (to name one).

PHP Functions
I have a serious problem, that I hope you here at DevShed can help me out. I have been using PHP for a while now and I love it, I think its a great language. I have learnt quite a lot already...but there is one thing that I have had trouble with and thats writing my own FUNCTIONS!

Im fine with the built in functions etc, but I just cant get my head around bloody USER DEFINED FUNCTIONS!

I have read books, completed many tutorials and just when I think I have it sewn up, something else crops up and Im back where i started.

I would be very grateful if someone could take me through the workings/example of a custom function.

e.g - echoing in a function, returning values.

Using PHP Functions On Different Url

I want to extract the size of images located at a different url

Is it possible to use the GetImageSize() function to do this?

from http://www.site1/myscript.php I have tried -

$url = "http://www.site2/image_name.jpg" ;
$size = GetImageSize($url);

But I get a error.

Is there a way of using functions such as GetImageSize(), chdir(), etc from one site to extract data from another site?

Both sites are mine and I have made the directories 777

The reason I want to do this is because I hold 100's of images on one site, but wish to use them on a second site without having to keep copying over all the images as it will be difficult to keep up to date.

But I need to use php to extract and minipulate the images before displaying.

Does any kind php guru know a way of doing this?

XML Functions With PHP
Anyone know where I can find some tutorials or good usefull examples on parsing XML with the XML functions? I really need help with this stuff, but I cant find any docs anywhere, help would really be appriciated.

C Functions To Use With PHP
We have a bunch of C and C++ functions pre-developed in our organization.

To make a web frontend, we would like to use PHP but we don't want to recode all the C functionality.

I recall reading a while back in the manual that C functions can be integrated into PHP, compiled perhaps, but I cannot seem to find it now.

Php-functions
Do any of you know if PHP supports a function to check a file. A same sort of function like in an Unix-environment the function "file" is: to check what kind of file a specific file is.

Functions
Is it possible to install new functions without reinstalling PHP,on a unix system?

XML DOM Functions
What about actually creating an xml doc on the fly, and saving it out. Does anyone know of any info or examples on this to point me to before I go hacking away with nothing but the xml dom function info from the manual? The manual is great, yes, but its usually the user comments that help in figuring this stuff out, and nobody talks about creating xml documents.

Functions!!
What I've done is I've got some code which displays the question and the wrong answer, however I'm trying to email the user who has set up the quiz, the info, which includes the wrong questions.

The thing I don't want to repeat the code, but rather place this in a function, but it looks rather tricky, when I try to implement this. Code:

Min And Max Functions
If I have a series of integers, how do I get the minimum (or maximum) value
NOT equaled to 0?

Web Functions?
I'd like to post some news content on my web page from another website. Are
there built in php functions that will allow me to do this?

Using Functions
I have this project and so far this is what it's suppose to do:
There are 4 pages.  The first page asks the user to enter their username and password (these are finite and defined by the second page) and asks the user to choose a file they want to work with.  The second page verifies the username and password are correct and echoes the information from the chosen file into a table and has two links underneath: one to take the user back to page 1, and the second to take the user to page 3.

Page 3 calls in two functions from page 4 to loop through all the information in that same file using regex to make sure Student Numbers and email addresses are in the correct format.  If it's correct, it will alert the user that all the information is legitimate, or else it will write the errors to a log file.  What I'm having trouble with is on page 3 and 4.  The functions aren't working because Apache says there are undefined variables, and on page 3 I can't seem to get rid of the array to string conversion notice. Code:

Sql Functions
i know:

year()
month()

is there one for week, ive tried week() but I cant seem to get it to work, is there a site I can look at sql functions?

MS-SQL Without Functions?
Within the following environment:
* MS Windows NT 5.0 web server
* MS-SQL database server
* PHP Version 4.3.3 (with MySQL functions, but without MS-SQL functions)

... is it possible AT ALL possible to connect to a database if my pages are all *.php?  I asked the sysadmin to configure PHP's MS-SQL functions, but he felt that it would require too much modification of the server.  He suggested I use ASP... is that even possible without switching all the files to *.asp (and making the existing PHP scripts useless)?

Functions
i've seen on alot of forums, such as PHPbb2, that in their template files, they use lines such as <!-- BEGIN switch_user_logged_out -->  I was wondering if you use functions to do that and if so, how?

Functions...
I'd like to ask two questions:

1) How can I include functions located on other files?
2) How can I make a function modify the values of passed variables?

I'm guessing there's something with references, but I'm not familiar with this concept on PHP, I just know C++ pointers, so if there's any good paper on it.

Writting Functions
Where does one learn about adding functions to PHP, not for development, more for personal, I know how to write functions in a PHP script, but where can I learn to write "global" functions?

Rename Functions
I run a site which loads images using PHP and MySQL to store the image information. Currently the system works as such:

- A table stores the name of the image, which basically is just the main part of the image filename that is loaded when you click on a link. eg table entry = "image1", the filename that is called on the site is "image1.jpg" so clicking the link shows that image.

Anywho... I'm looking to change the system so that the images are named as per the ID number in the table, so instead of "image1.jpg" it might be "0001.jpg".

So my question is this:

Is there a way that, when the image is loaded, I can create a button or link of some kind below it that says "Click here to save the image", and this would then rename it to the name field when they are saving?

eg

Table entry:
ID - 115
Name - image1

Image loaded:
115.jpg

So when they right-click to save that image, it will prompt to save it as "115.jpg" by default, which I don't want. I want the button to get the 'proper' name, eg image1.jpg, and put that in the box when saving, automatically.

I hope that makes sense, it's kind of hard to explain...

Does anyone know how this could be achieved if at all possible? Any help would be great!

Using The File Functions
I am working on a script that w3ill be used to create redirects or gateway pages etc.

The script creates a directory, then places a index.htm file insidce the created directory with database variables and a meta-refresh in the head of the HTM file. The creation of the dile is not the problem.

What I would like to know is how would I go about editing this file??

If someone logs in to the admin screen and edits the database entry for this redirect, what would be the easiest way to update the contents if the file??

Would it be easier to overwrite the file, or is there a way where I can open the file, read the file into a buffer until it finds what I want changed, make the change then move to the next point(Different Variables)?

Variables Within Functions
I had a bit of script which passed a variable to itself using GET variables. I changed it so that the <FORM> tag of the page was inside a function. Since then, the $HTTP_SERVER_VARS['PHP_SELF'] variable returns nothing.

Is it commonly known that this variable doesn't work inside a function? And how can I get by this (apart from passing it into the function).

p.s. I realise you can use $_SERVER variables, but i have to use this older version of PHP cos my ISP wont upgrade it quite yet!

Certain Functions Don't Work
I have just installed php on windows 2000 and it's working fine. But there are some functions that work and some that don't.
For eg: "mysql_fetch_array" will work fine but "in_array" will not work. Is there something more that I have to install so that these functions too can work?

Ssl In Socket Functions
Can I create ssl connection through the socket functions (not fsockopen)?

IMAP Functions
I have signed up with a new web host and want to use IMAP functions with them. They do support these. I have checked. They have provided webmail at url:

http://webmail.mydomain.com

so I guessed that I should use this syntax in my php script:

imap_open("{webmail.mydomain.com:143 INBOX", "username", "password");

But it does not work. I receive this error message:

Warning: imap_open(): Couldn't open stream {webmail.mydomain.com:143}INBOX

Help! I have asked my host about this and from their reply I dont think they even know what IMAP functions are. So, I am really stuck. I have read about opening an IMAP stream and that there are different syntaxes for different software components and scenarios - how can I find out which one is appropriate for my set up, given that asking my host is out?

The webmail is horde webmail. The login url is below

http://webmail.mydomain.com/horde/

I am on a virtual server. So, I have an IP - but it is a shared IP of course. My host provided me with 3 IPs - one for FTP access, one is just my private IP (behind a firewall), the other is a public IP (outside the firewall). I have to give my public IP to DNS.

Image Functions In Php?
I have seen some images (banners.etc) that have a src like
<img src='http://url/file.jpg?bla=bla&blabla=blah'> im assuming that the src isnt really an image but a script that echos out an image. my question is, on the server. the file extension is jpg... do u make your script executable and give it a jpg extension or what? how does on accomplish this?
also, could anyone point me in the direction of a server that supports the image functions in php? i currently am storing my scripts at http://hobbiton.org where they have php installed as a cgi. but with no image support...they provide 50mb free... so this is a pretty good server.

Calling Functions
Could someone out there give me information on how to call a function from a click event? Is it possible to do in PHP or do I need to write it in javaScript? What I would like to do is click the next record button and have all of the fields in my form change to hold the data of the next record in the table.

Functions Postgesql
can someone tell me the equivalent of the following function in postgesql from mysql functions:

1.mysql_result
2.mysql_data_seek
3.mysql_fetch_field
4.mysql_errno()]
5.mysql_error()
--------------------


Need Help Writing Own Functions
I would like to try writing my own functions, so as to keep some code
within the same PHP file rather than make multiple PHP files.

What I am having a problem is is how to call a function when a php
generated HTML form is "submitted" and to put the variables back into
another function within the same PHP file.

I have figured how to pass variables to a basic test function I wrote, but
not how to call a function within the same PHP file AND from a form.

Can't seem to find any good examples online.

Openssl CSR Functions
I have been playing with the openssl functions in php, but cannot figure out how to decode a csr. eg. I generate a csr then want to check the details are correct before submitting to ca?

Mail Functions In Php
i am using mail function in PHP.the mail address is a variable.Mail address will known at run time. My doubt is how to find out whether the mail address exists or not?

It had been specified in the PHP sites like mail function returns boolean value. I specified some address like mail(z@388dkd.com,"subject","message");it returns true.What's the way to find whether the domain exists or not?

Eval And Functions
Does anyone know how I can use a function within eval()? The situation is this: I am retrieving a string from a database like

'<P>HELLO <A HREF="www.xxx.com/$user/test.htm" </A></P>'

The data held in the database for the user must be mixed case, but I want to create the link all in lower case. Currently I do

eval("$code=strtolower("$code");");
echo "$code";

But this returns 'hello' with the link in lower case. What I really want to do is store the strtolower() function in the database and have it used by eval() to return the text in upper case and the link in lower like :

'<P>HELLO <A HREF="www.xxx.com/strtolower($user)/test.htm" </A></P>'

but all that happens is that eval() ignores the strtolower function.

OVERRIDING Functions
I want that every time the built-in 'mysql_query' function is called another user function is also called.

But i can't call the user function explicitly, I can only call the built-in function.

String Functions
strpos() is helpful because it will find the position of the first instance of the substring (the "needle") you're looking for in a larger string (the "haystack").

strrpos(), however, DOES NOT DO THE REVERSE. strrpos(), unfortunately, only takes a single character as a "needle," and not a string of any length like strpos() does.

This is killing me. Anyone know any easy way to find the position of the last instance of a (multi-character) substring in a larger string?

I'm trying to write a search engine. Ideally, the results will be truncated by ellipses (...) around the search term. The starting ellipses are easy; I just use strpos() to find the position of the first instance of the term. Finding the position of the LAST instance of the term is what's hanging me up.

Verisign Functions
I was just wondering if there was anyone with experience using the pfpro functions. Recently, I have had great difficulties moving a website from one hosting company to another... No one wants to install pfpro. I guess my specific question is, once PayFlo Pro is installed on the server can I use any of the functions assuming the version of php is >= 4.02?

Chmod Functions
I'm currenty developing a CMS library in PHP and MySQL. The thing I
wan't is a chmod like system on the forum; the categories and forums
work like *nix directories and threads as files. Does anyone have any
ideas on how I should construct the methods for read and write the octal
value.

An idea is the "chmod_read($int_octal)" returns an array;
array(read => true, write => false);

XML Entity Functions
How come there isn't a xmlspecialchars(), and for that matter,
xml_entity_decode()? I would think someone would have thought of that by
now.

Nested Functions...
I've inherited some code, which is not working as it is supposed to.

The way it's implemented has me confused.

It looks something like this:

Ssha Functions?
I am trying to use ssha does anyone have a good location for getting
it for php (4.3.X)

Using Header Functions In Php
i am trying to create code that will prompt the user to download.
below is the code i am using:

..
..
..

$content = datadump ("clients");

$file_name = "MySQL_Database_Backup.sql";
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=$file_name");

'datadunp' is simply a function that i have created to generate a sql
string from my databases and return the value into $content.

unfortunately, when i run this code from the server, it doesnt do
anything. i have noticed that i am gettin errors when i place the code
with the header function anywhere but the top of the document but even
without error, it isnt doin anything.

Why Doesn't My GD Functions Work?
I have installed Apache 1.3.12 and PHP 3.0.16 on a Win98 platform. I have set extension=php3_gd.dll in the php3.ini file, but still I get warnings like "Call to unsupported or undefined function imagecreatefrompng() in..." I've tried to find other versions of the file php3_gd.dll, but have not had any luck so far.

Session_register(); In Functions...
I have a function which outputs 2 Forms. After the first one an ID is generated, which I need after the 2nd form. So I register this var as a session var and define it as Global.

Testing with session_is_registered() shows that it actually got registered. Still after the 2nd form, the var isn't registered anymore! Again tested with session_is_registered.
I start the session at the top of each page. The whole thing works fine with cookies, but not with sessions.


Copyright © 2005-08 www.BigResource.com, All rights reserved