Make Function Equal To String In Conditional
I can usually figure something out, but I CANNOT figure this one out: This is a classified word ad script to count the words in a text area ($wrdad) and multiply it by the rate for how many times the ad will run in the newspaper. I know my code is messy and ameture, don't be too critical, but it works - everythign except one part. We have a 15 word minimum. I have this area commented out as //Problem Area/// in the code below.
In a nutshell, I want function wordcount($wordad) to be equal to 15 if there are fewer than 15 words in the $wordad textarea. It just seems to ignore the wordcount($wordad) == 15; in my conditional. Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
String Function In PHP To Make The Searching Of Tags
I not sure if bbcode was the term for this.. how this can be done? for example in this forum, with the open and closing some code here or [/img]link of image here[/img] and on the display it is display with a ceratin CSS/format or something..is this can be done through "eregular expression"? and before saving on the dbase is converted to <img src"" />? am I right? is there a string function in PHP to make the searching of tags easy?
Make Text String Read From Right To Left In Imagettftext() Function
I want to write a text string from right to left instead of from left to right with the imagettftext (); function I read in teh manual that the angle variable controls this, it says that 0 angle means left to right, so I tried 180, 360 but nothing happens What angle do I need to put it to get it to write it right to left I am writing a hebrew text string with a font.ttf that supports hebrew characters <?php $white = imagecolorallocate($background, 255, 255, 255); $fontfile = "davidtr.ttf"; $string = "מחלדגכ"; imagettftext($background, 12, 360, 3, 17, $white, $fontfile, $string); ?>
Make Associative Array Out Of String
I have a string that look something like this: $string = "weight, kg|1200|width, mm|220|prize|20000"; and I would like it to an associative array and print keys and value: weight, kg: 1200 width, mm: 220 prize: 20000 (The string above is fetched from a database) Anyone have any bright ideas how to do it?
Is It Possible To Make Your Own Function For Encryption?
I am sorry for bringing up *yet another* post about encryption, but I was just curious. Is there a way to make your own encryption function? I mean, that would make it more secure than anything, right? Since no one else would have that encryption key or whatever? Is there a way to look at the current encryption functions like MD5 or crypt? I know it's a lot more complicated than a=1 and b=2, but I think it'd be cool if I could come up with my own form of encryption (with the help of a professor, of course)!
Make Ip Block Function
I would make a ip block script for my site. The blocked ip are stored in a file. I have made the following script. Why does this not work. The file entries must be stored in a array and after that i must check all the fields in the array. Please help... <?php $ip = $_SERVER['REMOTE_ADDR']; $bestand = "ipblock.txt"; $open = fopen($bestand, "r"); $iparray = file ($open); $n = 0; while ($n < count($iparray)) { if ($iparray[$n] == $ip) { print ("NOT"); else { print ("YES"); $n++; } } ?>
Make $_SESSION Variables A Global In A Function?
i'm have a particular function where it creates session variables, yet after using this function i want to immediately use these session variables now I realize the only way to "use" variables that are made inside of a function is to make the variable a global variable so it can be used outside the function so i did this: global $_SESSION['userid']; global $_SESSION['username']; global $_SESSION['userlink']; global $_SESSION['userifnewmsgs']; global $_SESSION['userrank']; however there are many instances when !isset($_SESSION) , when the session variables are not already set i run this function when the sessions are not set and I get this: Parse error: parse error, unexpected '[', expecting ',' or ';' what's going on and how can I fix it?
Make Thumnails Of A Video - Ffmpeg Function GetFrame()
I have coded a script that makes thumnails of a video. here is my code: 10) $mov = new ffmpeg_movie($videospath); 11) $duration = round($mov->getDuration(),0).'s' 12) $height = $mov->getFrameHeight(); 13) $width = $mov->getFrameWidth(); 14) $image = imagecreatetruecolor($width,$height); 15) $frame = new ffmpeg_frame($image); 16) print is_object($frame)." obj1 "; 17) $frame = $mov->getFrame(1); 18) print is_object($frame)." obj2 "; 19) $image = $frame->toGDImage(); 20) @imagejpeg($image, $videospath.$vid.'.jpg', 100); This code works fine for some movies and makes the thumbnail image but for some movies it did not make thumnails and give the following error. 1 obj1 obj2 Fatal error: Call to a member function on a non-object in /home/iideshow/public_html/inc/makeVideoPics.php on line 19 In try to debug the error I add two extra statements in my code on lines 16 and 18 and u can see in the output before the calling of function $mov->getFrame(1); on line 17 the frame object exists but on line 18 it is not. Can any one guid me wht's the problem here. Remember it works on some videos but on most of the videos it did not.
Parse Part Of String (mid String Function ?)
Can someone tell me how to parse part of a string? I can use the following: <?php $text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url); echo $text; ?> to get this result: "Your currently at /test.php " I just want to get "test.php " without the dash. I also need to parse out parts of other strings. I know how to use Mid(), Left(), and Right() in VB, but no clue for PHP.
Two Equal Strings?
I was just checking php.net but couldn't find a function that will compare to strings. Did I just overlook it? or do I have to write a function to compare the two stirngs in php? If there is a function, which one is it? If there isn't a function, could you give me an idea of the coding that would compare two strings?
When To Use 2 Equal Signs And When To Use 3
When I had these two lines in my code: if ($executed == "The command didn't exist") { $this->core->error("In CommandRenderAllActionsInAnArray we sought the command '$commandName' but ExteriorCommands could not find it. It returned the value: '$executed'.", "CommandRenderAllActionsInAnArray"); I was getting this on screen: # CommandRenderAllActionsInAnArray threw this error: In CommandRenderAllActionsInAnArray we sought the command 'checkToSeeIfThisIsTheFirstLogin' but ExteriorCommands could not find it. It returned the value: Ƈ'. But if I change the first line to this: if ($executed === "The command didn't exist") { then it works correctly. Why does this need 3 equal signs? Why doesn't 2 suffice? I've done string comparisons before and I've never had to use 3 equal signs before.
Strcmp Vs Equal
I noticed in some examples to the encrypt functions of the PHP manual a syntax was used for password checks such as if (strcmp($userpassword, md5($_POST['password'])) == 0) { // do login } What is the advantage of this compared to if ($userpassword == md5($_POST['password'])) { // do login } ?
Making Fields Equal
I have two tables in a database and I have an html form. The tables both include a field called id# and that's how I have linked the tables in my SQL statement. I would like to set up my form so that when someone enters an id# it will write the value to the id field in both tables. Does anyone have any idea how I'd go about doing this?
How Can One Variable Equal 2 Things?
I'm having a problem that is baffling me... say I set a session variable as so: $_SESSION['temp'] = "default"; Now if I test the following two conditionals: if($_SESSION['temp'] == "default") and if($_SESSION['temp'] == 0) they both return TRUE. I don't understand why this is... if anything, I would have thought testing if it == 1 would be a boolean true since the variable exists and is not NULL, but testing if == 1 returns FALSE.
Two Variables, Equal Values - ?
After seeing a script programmed by a user in the beta-test section, I copied its premise - a man vs. dragon battle, with random damage being done. It just takes random numbers each time the page loads for damage values. That's all it does. However, whenever I play it, the end HP for both man and dragon are exactly the same. I need 2 things done, or at least to know how to do them - 1) I need to know how to fix the equal-HP problem 2) I would like it if someone could tell me how to achieve the effect of a <br>...tag within a PHP script. Here's the script! Code:
Equal Ratio Image With Netpbm
I'm trying to modify a script I am running for a gallery application. The script creates thumbnails properly, but only changes it based on width, which is a variable supplied in a sql table. I'm trying to modify the script so that it so that the width "and height" are no greater than that variable. Here is what I have so far: Code: <?php function RatioResizeImg($src_file, $dest_file, $gid) { list($dbconn) = pnDBGetConn(); $pntable = pnDBGetTables(); $column = &$pntable['meg_categories_column']; $query = "SELECT $column[thumbwidth] from $pntable[meg_categories] WHERE gallid=$gid"; $result = $dbconn->Execute($query); list($newWidth) = $result->fields; list($newHeight) = $result->fields; switch(megConfigGetVar('imageSoftware')) { case 'GD': return RatioResizeImgGD($src_file, $dest_file, $newWidth); break; case 'ImageMagick': return RatioResizeImgImageMagick($src_file, $dest_file, $newWidth); break; case 'none': return $src_file; break; case 'browser': return 'browser' break; case 'NetPBM': return RatioResizeImgNetPBM($src_file, $dest_file, $newWidth, $newHeight); break; default: return $src_file; break; } } function RatioResizeImgNetPBM($src_file, $dest_file, $newWidth, $newHeight) { /* Define where to find the various external binaries we need */ $netpbm = megConfigGetVar('netpbmPath'); /* default: home/www/pcmodeler/netpbm */ $djpeg =$netpbm."/djpeg"; /* decompresses a jpeg to ppm */ $cjpeg =$netpbm."/cjpeg"; /* compreses a ppm to jpeg format */ $pnmscale = $netpbm."/pnmscale"; /* scales a ppm image */ $pnmscale = $netpbm."/pnmscale"; /* scales a ppm image */ $jpgtopnm = $netpbm."/jpegtopnm"; /* convert a jpg to ppm */ $giftopnm = $netpbm."/giftopnm"; /* convert a gif to ppm */ $pngtopnm = $netpbm."/pngtopnm"; /* convert a png to ppm */ $ppmtojpg = $netpbm."/ppmtojpeg"; /* convert a ppm to jpg */ $ppmtogif = $netpbm."/ppmtogif"; /* convert a ppm to gif */ $ppmquant = $netpbm."/ppmquant"; /* colour quantize a ppm */ /* $imginfo = @getimagesize($src_file); if ($galleryvar['imageSoftwarePath'] == '') $cmd = $galleryvar['imageSoftwarePath']."/"; else $cmd = ""; */ if(!file_exists($dest_file)) { if(ereg(".gif$",$src_file)) { /* Look for .gif extension */ exec("$giftopnm $src_file | $pnmscale -width $newWidth ". "| $ppmquant 256 | $ppmtogif -interlace > "$dest_file""); } elseif(ereg(".jpe?g",$src_file)) { /* Look for .jpg or .jpeg */ exec("$jpgtopnm $src_file | $pnmscale -xysize $newWidth $newHeight". "| $ppmtojpg > "$dest_file""); } elseif(ereg(".JPE?G",$src_file)) { /* Look for .JPG or .JPEG */ exec("$jpgtopnm $src_file | $pnmscale -xysize $newWidth $newHeight".". "| $ppmtojpg > "$dest_file""); } elseif(ereg(".png",$src_file)) { /* Look for .png */ exec("$pngtopnm $src_file | $pnmscale -xysize $newWidth $newHeight".| ". "| $ppmquant 256 | $pngtopnm > "$dest_file""); } else { /* not a GIF, PNG or JPG file */ return(""); } } return $dest_file; } ?> So far, I can't get it to modify the width, so that portrait images are no larger than the variable. What am I missing?
Equal Height Columns With 1px Border
I need content boxes equal height with 1 px border, i tried this one http://www.positioniseverything.net...ple/equalheight , but i think it doesnt work standard for a 1px border, is it a good idea to measure the text with php to solve this?
No Libphp4.so File Created In Make Intstall Or Make.
I have done a make, and a make install on the 4.3.6 version, using /usr/local/etc/php as the directory I make from. However, no matter what I do, I do not see a php4lib.so that has been created. The documentation I recieved (an IBM source) says that the following has to be added to the httpd.conf file : LoadModule php4_modulelib/apache/libphp4.so .. .. .. AddModule mod_php4.c here is the output from my make install : [root@mail php]# make install Installing PHP SAPI module: cgi Installing PHP CGI into: /usr/local/bin/ Installing PEAR environment: /usr/local/lib/php/ [PEAR] Archive_Tar - already installed: 1.1 [PEAR] Console_Getopt - already installed: 1.2 [PEAR] PEAR - already installed: 1.3.1 Wrote PEAR system config file at: /usr/local/etc/pear.conf You may want to add: /usr/local/lib/php to your php.ini include_path [PEAR] DB - already installed: 1.6.2 [PEAR] HTTP - already installed: 1.2.2 [PEAR] Mail - already installed: 1.1.3 [PEAR] Net_SMTP - already installed: 1.2.3 [PEAR] Net_Socket - already installed: 1.0.1 [PEAR] XML_Parser - already installed: 1.0.1 [PEAR] XML_RPC - already installed: 1.1.0 Installing build environment: /usr/local/lib/php/build/ Installing header files: /usr/local/include/php/ Installing helper programs: /usr/local/bin/ program: phpize program: php-config program: phpextdist
String Function
I'd like to know whether there's a php function that transform a string into html... espacially turning to <br> etc. I couldn't find it in the php doc.
String Contains Function
Is there a function in PHP that will return a boolean if a String contains another given String. As what I am trying to do is disallow input that contains ../ or something else that would allow directory traversal.
Multi String Function
I am trying to create my own template engine.. nothing serious just for personal use but I want to make a certain function that I do now know how to make.. basicly it should work like this template($templatename, $var1, $var2, $var3); though the $var's will be different each time, so with one template it'll only be one var and with another 5.. and I have no idea how to get that done. I want the function to get the template from the database and convert [var1] to $var1 etc.
String 'starts With' Function
I have looked at the PHP string functions and I cant see any function to check to see whether a string starts with a certain letter or letters. Is there any way of doing this with the built in functions?
Returning A String From A Function
if (isset($search)){ return "<A HREF=javascript:popUp(emailsearch.php?mysearch=".$search.")>Email Search to Friend[/url]";} something wrong in my return statement. The popup window is not opening.
Translate String To Function Arguments
I have this: <headline size="2" color="#000000">Hello World!</headline> I have already done all the coding to pass this to a PHP function this way: function headline($content){ print "<span class='headline'>$content</span>"; } So the <headline...> example would result in: <span class='headline'> Hello World!</span> So far so great. But you might have noticed the arguments in the original string? I want to pass those! I would prefer to have them this way: headline("Hello World", "color=#000000", "size=2"); And then extrat them with func_get_arg(). But how do I translate a string to seperated arguments for a function?
Correct XML String Creation Function
Is there a php function that can translate any string to it's correct XML equivalent? Like for instance when I have the following script: PHP Code:
Function To Find 6 Digit Numeric String
I need to parse a string and attempt to find a substring in the string that contains 6 numeric digits. the first and last digit may or may not be preceded by a space. I need to find the starting the ending positions of the 6 numeric digits to that I can extract the string and build an href containing the string and replace those 6 digits with a hyperlink.
Conditional Loop
I have one table, "players" that has player info including start season (year). I then have a table for each season with player stats, i.e. games played etc called stats200X where X is the year obviously. I have no problem with extracting data from the current year, but what I would like to do is get data from previous years too. I was thinking about doing something like: (year) - (startyear), which for example could be 3. I don't know where to begin, but I want to be able to loop though previous years so that, if tables exist of course, I could do select * from stats{Y -1} display select * from stats{Y -2} etc Would I need to hard code this or is there a way of doing this though a conditional loop?
Conditional Login..
I have a form with a username & password field along with 3 radio buttons. What I basically want to achieve is if radio button A is checked it will post the username & pass to a.php, If button B is checked it will post the username & pass to b.php and so on for button C.
Checkboxes,conditional
Basically I have what seems to be a very small problem but I am driving ny self mad trying to figure out what the problem is. Here is what I have: I have a form with two checkboxes: <input type="checkbox" name="medicalcheck" > <input type="checkbox" name="dentalcheck" > the form is posting the a php file, decision.php, that simple checks to see if the boxes have been checked and performs an operation in either case. Here is the code:
Once Conditional Causes Error, The Other Doesn't...why?
There are 2 if statements at the beginning of this code snippet. The one that is currently commented out works while the one that is not commented out yields this error Parse error: syntax error, unexpected '{' in C:xampphtdocsench2index4.php on line 106 I am just not seeing why. Code:
Conditional Structures
I am wondering about conditional structures and the depth of nesting allowed, if at all. For example I know I can do this: Code:
Conditional Form
I want to condtionally display an HTML form. I havnt got a clue how it can be done, I suppose its the same way as putting html tables in php, but I cant get it to work. Here is the condtion: <?php if (!empty($pk)) { And here is the form: <form action="google.php" method="GET" name="deleteForm" > <input type="hidden" name="pk" value="<? echo $pk;?>"> <input type="submit" value="Delete"> </form>
Conditional Third Expression In For Loop
Is it possible to make expr3 $i++ under one condition and $i-- under another? Instead of having the condition outside the loop and having two loops. Or I could just use a while loop, I guess.
Sessions + Conditional Include
I am having a little problem in trying to figure out why my session state is not expiring after I close the browser window. Having been used to the ASP way of doing things I am trying to get my head around this slightly different method of handling sessions in PHP.... What happens is that I log on to the site, do various things and then close it when I am finished. I return the next day to find that the 'logged in' menu is displayed first which shouldnt happen until you have logged in again. I assumed that the session was been stored as a cookie but wasnt been released after the session terminates by default, but found I was wrong when I deleted all my internet files and went back to the site. My code for the first page is as follows..
Conditional PHP Cookies; If Cookie = 1 Do This...
I've figured out cookies ... now I'm trying to combine them with if conditions. For cookie 'bandwidth1' I want to echo that it is set to 1 by the cookie to confirm this in the brower through regular html. My if/else statements don't seem to be working though...heres the code I have now. <?php setcookie("bandwidth1","0",time()+2592000,"/"); setcookie("bandwidth2","1",time()+2592000,"/"); setcookie("bandwidth3","2",time()+2592000,"/"); ?> <?php if (isset($_COOKIE["bandwidth1"])=="1") echo "Bandwidth is 1!"; else echo "Bandwidth is unknown"; elsif echo "Cookie was not set?"; ?>
MySQL Conditional Statement
What I am trying to do is kind of like an advanced search. Basically, I have three dropdowns, for this I am going to use the example books: Three dropdowns, which are 1) Author 2) Language 3) Type (Hardback or Paperback) Typical search: I want to get a list of all books written by STEPHEN KING, that are written in ENGLISH and that are HARDBACK ok fine, but what if I just want to search for ALL books by STEPHEN KING regardless of the language or the type of book?? Heres the SQL i would use for all 3 "search parameters": PHP Code:
Writing Conditional Statement
I'm trying write a conditional statement that updates the database in 1 of 2 ways depending on the values given. I'm only 2 weeks into learning PHP/MySQL so I realize the way I've written it out is probably sloppy and more inefficient than what it could be. I've just been winging it from examples and trial and error and have gotten everything working except for this. I'm not sure if I have my logic or syntax wrong. Application-specific details: This is a simple invoicing application. Every invoice is in either 1 of 3 states: - pending (default state when a new invoice is entered) - paid (state when invoice is paid in full) - partial (state when only partial payments have been made on the invoice) What I'm trying to do is this: 1. If a partial payment is made on an invoice, the status is set to 'partial' (this is working) 2. If the payment posted was the full amount of the invoice or the final amount needed to pay it in full, the status is set to 'paid' (this is not working) My processing logic works like this: 1. There is a total invoice amount stored in the invoice table represented by $total variable (working) 2. When payments have been made to that invoice (stored in the payments table), I show the remaining balance on their invoice by calculating the sum of those payments and subtracting them from the total (this is represented by the $diff variable and is working) 3. The part not working: When the remaining balance ($diff) minus the payment amount posted ($_POST['amount']) is equal to 0, the status is set to paid. PHP Code:
Conditional Statements And Loops
Not long ago I was asked to give PHP lections to some private IT school. I'm on second lection now, and will be teaching my :) students conditional statements (if..else and switch) and loops (while and for). That was my story, now the question. Can you give me an advise on some geeky use of those statements to stir up some enthusiasm in students.
Mutlipart And/or Conditional Form
I have a form that needs to have conditional statements, and I am not sure how to "fix" this. The existing form is split in two parts - the form, and the processor. I would think that I will need to combine them, but.. Anyways - what I need is somewhat simple - if a certain option (from a <select>) is chosen, force another field to be completed. I also have 2 other fields that if the radio button is set to YES, require new fields. Ideally, the optional fields would only be shown to the user IF they are required.
Conditional Select From Mysql
I have a mysql database which stores race data that I want to open up to users for viewing. I want the user to be able to select various subsets of the data according to the parameters: race, gender, age, and type (and maybe sometime, by name as well). This is BOTH a mysql question and a php one, as I ask for a more efficient solution (see bottom this post). Here is a snippet of how I am implementing the mysql statements to select only the exact subset of data. PHP Code:
Conditional Preg Match
The following bit of code does a preg match and does something if true (sets $browser to ppcie) Without using if then and else's how do I code it so it does not equal what it is testing for? So if it does not find ppc in the $agent then it does something else/sets it to something else? $agent = getenv("HTTP_USER_AGENT"); if (preg_match("/PPC/i", "$agent")) { $browser = 'PPCIE' }
Question On Conditional Statements
I'm a perl programmer and am trying to learn PHP. So far I have figured out most of the differences, but have not been able to find out how to do the following: When running through a loop, how can you test two separate conditions against the same $element of an array. For example, this is how I thought it would be done (similar to Perl), but it did not work: if (eregi("apple", $line) and (eregi("orange", $line) { do whatever; } Basically testing each line of an array to see if both the words "apple" and "orange" are present. Also, is there any equivalent to the following from Perl while running through a loop: next if (whatever conditions); last if (whatever conditions);
|