473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Optional $_GET argument

In this random practice script I was doing, I was passing some variables to the script with the URL, which means the $_GET method.

[PHP]<?php

header("Content-type: image/png");

$textinput = $_GET['input'];

if ($_GET['size'] == '')
{
$textsize = 24;
}

else
{
$textsize = $_GET['size'];
}


$height = $textsize + 30;
$canvas = imagecreate(800,$height);
$white = imagecolorallocate($canvas,255,255,255);
$black = imagecolorallocate($canvas,0,0,0);;

$ycoord = $height * (3/4);

Imagettftext($canvas,$textsize,0,0,$ycoord,$black, 'SEGOEUI.TTF',$textinput);

imagepng($canvas);


?>[/PHP]

It's a image generation script that outputs some text as an image. (Obviously)
It works perfectly, all except for this problem:

I want the $_GET['size'] argument to be optional. However, if you don't pass "&size=" to the script, it dies because of the undefined index of $_GET['size'].

Basically, I want to make it optional so that if I don't pass it a size, it should just set the size to a default of 24 and continue on.
Jun 6 '07 #1
2 5760
jx2
228 100+
well it does work well on my server... (except for a font )

i dont see any problems so it might be due to configration of your PHP

if u believe that unspecify size cos truble u might try : if(!$_GET['size'])

regards
jx2
Jun 6 '07 #2
ronnil
134 Expert 100+
you can always use isset().

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_GET['size']))
  3. {
  4.     $size = $_GET['size'];
  5. } else {
  6.     $size = my_standard_size
  7. }
  8. ?>
in other cases where you might wanna swallow a possible error, you can always use '@' in front of the variable/function. e.g. @$_GET['size'] won't produce an error even if there is one, I believe it returns null...?
Jun 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Philip Rittenhouse | last post by:
I have discovered a couple of problems with the way the universal gateway code handles optional parameters and variable argument lists in COM servers. It appears to only be a problem when you...
2
by: Exyle | last post by:
I have a function that has two arguents, however depending on the value of the first argument, the second one may or may not be needed. If I only input the first argument when calling the function,...
4
by: Gerry Abbott | last post by:
Hi All, Im trying to use thie combination but have not had success. Below is the function It tried the following myriskLevel(2,2) myrisklevel(0,0,2) and the ismissing(Three) alwasy...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
1
by: Doug Zody | last post by:
How to make function argument as optional in Vb.Net? I have a function signature as shown below. I am using .Net Framework 1.1. Public Shared Function Foo(ByVal strCustNo As String, ByRef...
3
by: Marco Segurini | last post by:
Hi, Actually I am calling from VB some functions imported from a c++ dll. Some of these functions require as parameter a pointer. Example: extern "C" int DllCall(int * pvInt, int iLen); ...
4
by: Joe HM | last post by:
Hello - I realize that there is no more IsMissing function in VB.NET but how can I have a boolean argument that is optional and in the code I need to determine whether it was passed it or not? ...
6
by: Rob Hoelz | last post by:
So these two functions are different: void foo(void); and void foo(); because the first one allows no arguments, but the second does. My question is: In the implementation of the...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.