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




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).




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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

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.

Calling Functions
Can I call function like they are called in JavaScript, in events like Onclick and so on.
for examle like this: <input type='submit' value='remove' onclick='remove($current)'>

Helper Functions
I have a colleague who is converting from perl to php and says he cannot believe that php does not contain helper functions. For example, when creating a scrolling select list a helper function will create this for you with a few defined parameters, whereas with php it appears you have to write the html in a loop.

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:

SNMPv3 Functions
I need to poll SNMP variables from Cisco routers using SNMPv3 (security
reasons).

I'm trying to use the little-documented SNMPv3 functions (see
http://us3.php.net/manual/en/ref.snmp.php, where argument lists seem to
be truncated, and
http://zugeschaut-und-mitgebaut.de/...snmp3_get.html).

I can get snmp3_get function to work fine, but when I try snmp3_getnext
I get a "Fatal error: Call to undefined function" error... does this
mean that function is not compiled into the system? Seems strange that
snmp3_get is and snmp3_getnext isn't... How can I go about confirming
this? And fixing it? Any pointers will be much appreciated!!!

More details follow:

jschnack@maxwell ~/develop/srt $ cat snmpv3-test.php
<?php
$desc = snmp3_get('x.x.x.x', 'snmpuser', 'authPriv', 'md5', 'password',
'des', 'password', 'sysDescr.0');
print "$desc";
?> ......

Dir Navigation With Php Ftp Functions
I'm having trouble navigating my directory structure using php's ftp
functions (such as ftp_chdir and ftp_cdup.) I'm writing a program that
allows a user to easily create robot.txt files and upload them to
their server. They should be able to log in to their server using ftp
and browse their directory structure, specifying which robots to allow
into each directory.

When the user logs into their server, they are presented with a list
of directories displayed as links. Clicking a directories link will
take them into that directory and will present them with the
sub-directories contained in that directory. I have the program
running at

Each time is link is clicked, the page is refreshed and ftp_connect
called, meaning that the user is logged back in to their root
directory. I have a stack containing the directories that have been
navigated, so that the program can direct the user to the drectory
they intend to be in.

This seems overly complicated. Is it possible to do what I am trying
to do just using php's ftp functions, without storing a session
variable containing all the directories that have been navigated? Is
is possible to not have to re-login to the root directory every time a
page that uses ftp functions is called?

The solution I have seems to work well and handles symbolic links, but
has the drawback that I can't navigate above the directory that the
user originally logs into. It also just doesn't seem like the correct
way to do this. I'm sure there is a simpler, more proper way.

<?php

include 'include.php'
session_start();

//If $_POST variables are set then we are logging in for the first
time and set $_SESSION variables accordingly
if (isset($_POST['server'])) {
$post = clean_post($_POST);
$_SESSION['ftp_server'] = $post['server'];
$_SESSION['ftp_username'] = $post['username'];
$_SESSION['ftp_password'] = $post['password'];
//Create a stack/array which holds the name of the directories we
have traversed
$_SESSION['directories'] = Array();
}

//if we are not connected to a server then redirect to the login page
if (!isset($_SESSION['ftp_server'])) {
header("Location: login.php");
exit;
}

//If $_GET variables are set then we are actively navigating the
directory structure
if (isset($_GET['dir'])) {
$get = clean_get($_GET);
$ftp_dir = $get['dir'];
}

// set up a connection or die
$conn_id = ftp_connect($_SESSION['ftp_server']) or die("Couldn't
connect to " . $_SESSION['ftp_server'] . "<br>");

// try to login
if (@ftp_login($conn_id, $_SESSION['ftp_username'],
$_SESSION['ftp_password'])) {
echo "Connected as " . $_SESSION['ftp_username'] . "@" .
$_SESSION['ftp_server'] . "<br>";
$_SESSION['username'] = $_SESSION['ftp_username'];
} else {
echo "Couldn't connect as " . $_SESSION['ftp_username'] . "<br>";
}

// turn passive mode on
ftp_pasv($conn_id, true);

//If we are navigating the directoty structure
if (isset($ftp_dir)) {
//if we are navigating to the parent directory pop the name of the
current directory off the stack
if($_GET['act'] == 'cdup') {
array_pop($_SESSION['directories']);
}
//otherwise we are navigating to a child directory
else {
//grab the name of the current directory and push it on the
$_SESSION['directories'] stack
$pieces = explode("/", $ftp_dir);
$relative_path_dir = array_pop($pieces);
array_push($_SESSION['directories'], $relative_path_dir);
}
//Since the stateless nature of http forces us to always login to
the root directory
//we use the $_SESSION['directories'] stack/array to navigate to
child directory we are trying to access
foreach($_SESSION['directories'] as $rel_dir) {
if (ftp_chdir($conn_id, $rel_dir)) {
//do nothing for now
} else {
echo "Couldn't change directory
";
}
}
//we are in the child directory, so display the path
echo "Current directory is now: " . ftp_pwd($conn_id) . "
";
}
else {
//we are in the root directory, so display the path
echo "Current directory is now: " . ftp_pwd($conn_id) . "
";
}

function create_dir_tree() {
global $conn_id;
$files = ftp_nlist($conn_id, ""); //get files in directory
if(is_array($files)) {
//display a link to the parent directory
echo "<br /><a href=index.php?&act=cdup&dir=" . ftp_pwd($conn_id)
.. ">parent directory</a>";
foreach ($files as $file) {
$isfile = ftp_size($conn_id, $file);
if($isfile == "-1") { //Is it a directory? (as opposed to a file)
//display a link to each child directory
$string = "<br /><a href=index.php?&dir=" . ftp_pwd($conn_id) .
"/" . $file . ">" . $file . "</a>";
//replace any double slashes with single slashes
$url = preg_replace("////", "/", $string);
print $url;
}
}
}
else echo "<br /><a href=index.php?&act=cdup&dir=" .
ftp_pwd($conn_id) . ">parent directory</a>";
}
?>
<html>
<head></head>
<body>
<table border="1" cellSpacing="3" cellPadding="3" width="100%">
<tr>
<td>
<?php create_dir_tree(); ?>
</td>
<td>
<form method="post" action="create_text.php">
<table border="1" cellSpacing="3" cellPadding="3" width="100%">
<tr>
<td>
<ul>
<li><input type="checkbox" id="all" name="all">* (all
spiders)</input></li>
<li><input type="checkbox" id="googlebot"
name="googlebot">googlebot</input></li>
<li><input type="checkbox" id="askjeeves"
name="askjeeves">askjeeves</input></li>
<li><input type="checkbox" id="slurp" name="slurp">inktomi
slurp</input></li>
<li><input type="checkbox" id="scooter"
name="scooter">altavista scooter</input></li>
<input type="hidden" name="path" value="<?php echo
ftp_pwd($conn_id) ?>"></input>
</ul>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="Submit"></input>
<input type="hidden" name="activity"
value="logging_in"></input>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

<?php
// close the connection
ftp_close($conn_id);
?>

Help With Imap Functions
imap_fetchstructure -- Read the structure of a particular message

a query about this function.....
(from php manual)
Description
object imap_fetchstructure ( resource imap_stream, int msg_number [, int
options])

This function fetches all the structured information for a given message.
The optional flags parameter only has a single option, FT_UID, which tells
the function to treat the msg_number argument as a UID. The returned object
includes the envelope, internal date, size, flags and body structure along
with a similar object for each mime attachement. The structure of the
returned objects is as follows:

so if i call imap_fetchstructure($imapstream, $msgNum, FT_UID)

it will treat $msgNum as a messageID?? yes or no and if no then how do i get
this to work.

"The optional flags parameter only has a single option". to be hoonest i do
not understand this optonal flags section.

Financial Functions
Are there any existing financial functions such as PV, NPV, IRR etc? I could write the functions my
self using PHP, but having prebuilt functions makes my work easier...

IRC Gateway Functions
Does anyone know a good tutorial on how to use the IRC gateway functions in PHP?

Queries, Functions
i am getting one of those 'mysql_fetch_object(): supplied argument is not a valid MySQL result resource' errors with the following code. the query is valid, because if i echo itself outside the function it prints the results, but if i call the function i get the error. here's the code on my php file. PHP Code:


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