laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
I believe ya wud have to strip the whole number and than work with the rounding for the fraction... $num=1.74; $fract=$num-abs($num); than the easiest way is using if..else... construct if($fract>=.75) $fract=1; elsrif($fract>=.25) $fract=.5; else $fract=0; than add the whole number and the new fraction together $num=abs($num)+$fract; well thats the simplest I can think of at the moment; a lot of this can be cut down significantly, but wasnt to keep example of how it can be done and still readable; $num=1.24999; $num=(abs($num))+(($fract=$num-abs($num))>=.75?1:($fract>=.26?.5:0))); careful that was done off the top of my head so there maybe a missing ( or ) but ya gets the idea
-
Why can't I use the GET method on a mod_rewrite'd page?
laffin replied to dezkit's topic in Apache HTTP Server
well think of a better system, instead of the catchall situation yer making. home?link=hello lends me to believe ya have different pages home page1 page2 so question is if u have home.php page1.php and so forth, why do u need link parameter? so the question ya pose makes no difference, as nobody knows the design or purpose. once ya come up with a purpose & design, than ya can begin the coding. -
I think this will work as well $string=preg_replace('@[^\w-]@','',$string) remember yer not just dealing with = \ u may get other characters that u may not want as well, so easier to assign a list of valid characters, and use the NOT operator. I think \w handles AlphaNums, _ can't remember about - & .
-
PHP Login - redirect to user profile *Help Please*
laffin replied to ryanwood4's topic in PHP Coding Help
<?php // replace with login/username validation $user='joe'; if(empty($user)) $userpage='login.php'; else $userpage="User-$user.php"; header( 'Location: http://www.yoursite.com/'.$userpage ) ; ?> simple redirection. -
Wrong way, he wants to remove anything but a-z 0-9 - . yer regex '\w-' matches those characters, which are valid filename characters so ya have to strip out everything else
-
i think the regex ya need is '@[^\w=-]@' which just grabs the characters not in the list note delimeters, and alpha's explanation above.
-
PHP Login - redirect to user profile *Help Please*
laffin replied to ryanwood4's topic in PHP Coding Help
Then question becomes how are you saving their profiles? either file or db based. if u store their pages/profiles in a db, than its just a simple matter of formatting the page if u have a file based system (either filebased username.html or folderbased username/index.html), u can simply include the file from the profile page. but u should have a system, to validate the pages. Safe javascript, no php scripts, etc, or use a custom markup language. otherwise ya will get a few users who will attempt to use em in a bad way. -
My Suggestion is avoid sessions/cookies. the PHP_SELF var is a good idea as well as using a constant in yer main pages so in yer included files, a simple check for the constant can break with an error main.php <?php define('PAGE','main'); include('includes.php'); ?> Success includes.php <?php if(!defined('PAGE')) { die('Illegal Access'); } // Rest of include ?> Very simple technique Nice thing about it, is that u dont need to do a page lookup against PHP_SELF. Good Luck
-
it's possible either use strpos or preg_replace. with strpos, u can use substr, to catch the prefix/suffix of that comment block. (2 strpos,2 substr) with preg_replace, well ya just replace it with an empty string.
-
1) a quick md5/crc32 function are out there already 2) diff can spot differences in text files, there is a binary diff app out there used as well. php could be used to recurse the subdirectories, and pass the info to md5/crc32 generator. and so forth. so it's not impossible, but it may take awhile. but php is just an interpreted language, so a compiled language (c/c++/c#) will definately give better performace. good luck
-
and how is preg_match supposed to extract the information? if the information isnt in the link u provided? http://www.facebook.com/profile.php?id=1447195962 See no name, just userid u wuf prolly have to use curl or fopen in order to retrieve the page and parse the page itself, or see if ya can get a redirected url link instead as they do http://it-it.facebook.com/people/Leila-Mod/1447195962 which has their name and userid.
-
Than ya don't do it on a random basis. U make a deck, than shuffle the cards, than deal the cards. its the same thing as if ya was playing live game, dealers dun just grab a card from thin air. they grab it from a pre-shuffled deck.
-
if yer using *nix use the & doohickie, if yer using windows, ya need another app to start the app in the background. php will not run apps in the background, that for the OS to do. Shell/exec return after the command is finished, reason ya use the & to put the app in the background in *nix machines.
-
My experiences with PHP started with Torrent Trackers, At first I had used a precompiled tracker and it was nice to start as a tracker but severely limited as to what u can do with it. I was than introduced to TBDev.net A torrent tracker that was written in php. So I started modifying the script to do whut I wanted, small modifications at first. which grew into bigger and more complex modifications. It was great to take an existing project, go in and start making modifications to what u wanted (As original script code is a very basic tracker community script). The TBDev community helped along the way when I had questions, or needed a fresh set of eyes to look at code. Or if they had questions, i could throw my two cents in. Been over 3 years, and i still participate in that community, even tho i do not run a tracker anymore....
-
U will be looking at 3 debuggers that I know about Zend I have used Zend Studio, its a great ide, howver it's slow (Java). But still is one of the best environments out there, the debugging facility is top notch. NuSphere I have used PHPEd with NuSphere's Debugger, its not bad but it does have a few faults that Zend has no problems with. Easily recognized by the DBG Listener tool XDebug I havent used at all, but due to some recent decisions, I thought I wud try a smaller development environment and started looking for tools to build a minimal environment. Taking a post about this development environment taken from another forums, which explains a lot more. So Far its a great setup (Except a bug I encountered, cant view a page in browser when ide is also open). But thats okay as devphp2 does have its own integerated broswer (IE & Mozilla). Other from that it does a pretty good job.
-
or ya can expand on the regex to capture 3 digits after an initial 1-3 digit capture ^\$?\d{1,3}([ ,]?\d{3})*(\.\d{0,2})?$ I believe thats correct
-
why the [\$] if its not a range of characters? take a look at some patterns for example of the same value with your different formats 12345678.90 $12345678.90 $12,345,678.90 12 345 678.90 $12,345,678.9 Since these are all gonna be individual strings, And we are checking the whole string. we start with ^ to signify the start of the string the $ is optional, regex has different designators, no designator = just once * = any number (0+) + = one or more (1+) ? = zero or one in this instance we want ?, but ya was right ya have to escape the '$' as it has significance in a regex pattern so next set is $? now comes the tricky part, cuz ya not shure how many digits are gonna be involved or if a seperator will be used. but we do know, the pattern of numbers usually looks like: \d?\d?\d[ ,]? if ya look at the designators above, we have optional digit optional digit and digit followed by either ' ' or a ',' but we need to repeat this cycle an unknown number of times, we can assign this as a capture group and give the capture group a designator as well (\d?\d?\d[ ,]?)* btw did u notice we can assign all those \d's a designator as well? instead of looking each one individually, we can assign a range to the \d, since we know we will always have 1, to a max of 3. we use the range designator {min,max} so now it looks like (\d{1,3}[ ,]?)* now to finish off our regex pattern with the cents, if its there, we can use the capture trick or do as u have done, lets go with the capture group to show the other way? (\.\d{0,2})? and of course, the last part, the end of string delimeter. $ so know ya shud have a pretty complex regex, that can figure out the differences of the same value with different layouts ^\$?(\d{1,3}[ ,]?)*(\.\d{0,2})?$ I Believe that does it
-
Final year project, please point me in the right direction
laffin replied to oriental_express's topic in PHP Coding Help
This was one of the reasons for my post, multi-dimensional arrays are good but ya need to know how to work with them. as well as the file parsed may not begin with 1 as the index, it could begin with 412. which means finding the correct array becomes a search routine. From the looks of it, you definately need a guide on working with arrays. and that is wut u shud google, not a quick fix for the code. In order to understand how arrays work, and thus yer own knowledge ya should google: using arrays php guide -
Final year project, please point me in the right direction
laffin replied to oriental_express's topic in PHP Coding Help
Well have to look at the pros and cons of each routine 1) $questions contains all the items. the file parsing is easier to code the search code is a bit harder to code Multidimensional array 2) $questions contains just the item needed the file parsing is harder to code as it has the search parsing as well No search code needed Single array and since the page reloads, ya may consider doing the search within the file parsing. -
Final year project, please point me in the right direction
laffin replied to oriental_express's topic in PHP Coding Help
A common case of overcomplicating the simple. -
Final year project, please point me in the right direction
laffin replied to oriental_express's topic in PHP Coding Help
u can look at the data structure, the code looks good <?php $file = fopen("questions.txt", "r"); while (($data = fgetcsv($file, 1000, ",")) !== FALSE) { $questions = array($data); } fclose($handle); print_r($questions); ?> the print_r function is a great diagnostic tool when dealing with arrays. so ya can visually see yer data, now with that as a tool, ya can build more logic on getting to wut ya want from the data. ya still need the form processing... -
Final year project, please point me in the right direction
laffin replied to oriental_express's topic in PHP Coding Help
Been following the progess. Michl doing a great job as per the references. As stated the format of the file is fine. But u need to parse the file for the index ya have in it either reading in the whole file into an array. or parsing the file until u get to the index ya need to be at. and for that u will need a loop structure. the form looks good, but now ya need to grind out the logic to the engine. Look at yer csv file. Remember fgetcsv only grabs 1 line at a time from the file. Ya still need, $_POST routine in order to get the user input as well... -
Final year project, please point me in the right direction
laffin replied to oriental_express's topic in PHP Coding Help
notepad does great But I prefer a lil more power in my editor (UltraEdit) But there are some pretty good freeware editors as well.... To me looks like the csv isnt gonna be changed after initial, since its a school project and wasnt mentioned in first post. seems like a fun project if he were to go all out, add in an editor / updateable.. reminds me of an old program that came on Apple DOS Animals.bas. -
u have to add more logic to yer template system, especially on forms. I was working on a template system awhile back, its pretty good. modules had different pre / main functions. to decide whether to process forms / show errors / display forms / load different page according to form data First ya have to figure out a way to give which step ya are on. such as http://www.site.com/index.php?p=register wud check for any POST information No Post Info ---> jump to display page (form) else process post info is post info ok? Yes, Change the Page load to main/index (or redirect) No, save error codes for form display Display page (form)
-
if ya have access to cpanel, ya shud have access to cron thru cpanel interface. if ya have that, ya can setup a php script to post current crons and check another file for any updates than as e3d said, ya have a web interface, which checks current crons as well as post the updates... actually sounds like a fun project. but if ya dun have access to cronjobs, ya wud have to go with a pseudo type cron, which is run on page loads instea, it works, but it wont run at the exact time. on popular sites, this system isnt bad, but on low hit sites, it can be awhile before it updates.