laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
Maybe something different. This removes the <p> tags throws in some css styles for the story and for the read more link <head> <style type="text/css"> .story {color:sienna} .readmore {color:blue} </style> </head> <?php $prel = "<p>This is my press release. It is pretty generic.</p> <p>It really doesn't tell you anything interesting</p>"; if(!preg_match('/\<p\>(.*)?\<\/p\>/i',$prel,$pr)) $pr=null; else $pr="<span class=\"story\">{$pr[1]}</span> <span class=\"readmore\"><a href=\"story.php?id=1\">... Read More ...</a></span>"; echo $pr; ?> Yes, I could have left the <p> tags in place, but that drops the read more link. I guess ya can put them back in:)
-
ya see why ppl like regex if(!preg_match('/^(\d{2,2})-(\d{2,2})-(\d{4,4})$/',$dat,$pieces) { $goof_msg = "Date error: yyyy-mm-dd format is required boss<br />"; } bout the only difference is the $pieces, return an array of: 0: (01-05-2009) 1: (01) 2: (05) 3: (2009) yep, 0 index should be the same as $dat
-
No, he said; Update your variables before Updating the DB.
-
Ya know never thought of doing that before. But it does work a simple example <?php $tp=$_SERVER['PHP_SELF']; if(isset($_GET['data'])) $data=htmlspecialchars($_GET['data']) ?> <a href="<?php echo $tp; ?>?data=<?php echo urlencode("The quick fox jumped over the lazy dog"); ?>">Lazy Dog</a><br /> <a href="<?php echo $tp; ?>?data=<?php echo urlencode("I'm a little teapot short and stout"); ?>">Tea Pot</a><br /> <textarea name='data'><?php if(isset($data)) echo $data; ?></textarea> Note the use of urlencode, to encode my data for usage in a url.
-
http://en.wikipedia.org/wiki/Roadsend_PHP
-
I took another look. Its in the javascript, u can get a list of users from This Link But this seems more like a site for sale than a php project, and if thats the case u shud look into freelancers
-
How do u perform login/logout detection?
-
annoying error - cant get login script working!
laffin replied to foxboro's topic in PHP Coding Help
I wud add a bit of debugging. $result=mysql_query($sql) or die("Error (".mysql_errorno()."): ".mysql_error()."<br>"Query='{$sql}'"); I think is correct. -
Problem is it doesnt go in sequence, reason I posted the 2nd code. 10 images per directory? I guess it depends on yer client base. if ya have <100 ppl than that may work well. but if yer allowing ppl to upload images, this may create another problem for u. mainly navigation and maintainance. Why isnt this using a database instead?
-
SQL will use more resources than a filebased system. if done right, the filebased system can be faster as well. Question is how to u plan on flagging online users. and wut the deletion system is gonna be. Options FileBased, More Code SQLite, Simple and effective, close to full SQL. FAST. Supports File/Memory Based Operations. MySQL, using Memory tables. MySQL MEMORY/(heap) It really depends on the operations required. and how insertion/update/deletion code will operate (more php or more sql) SQLite is kinda nice alternative, uses a flat file DB, if your not using the memory model. Is fast, and comes with php 5.0>
-
I think this is going wrong way, we are dealing with unknown folders in a specific folder and processing them. but I think he wants em in sequence. so creation of new folders is simpler $base=''; $folder=0; do { $folder++; $sub="{$base}/{$folder}"; if(is_dir($sub)) { $files=scandir($sub); foreach($files => $file) if($count<=10 && is_file("{$sub}/$file")) $count++; } else { $count=FALSE; break; } } while($count>10); if($count==FALSE) echo "No available folder"; elseif($count<10) echo "Folder {$folder} available"; else echo "All Folders All Full"; This just works if the folders exists, numbered 1..xxx and will go thru them 1 by one, checking if each dir has 10 files or more. it will stop until a numbered directory is under 10 files or there are no more numbered directories to process. Shud be easy enough to modify
-
serialize/unserialize/file_get_contents/file_put_contents. remember to give the file read/write permissions.
-
So yer saying I should question the fuinction library of php. Than wut use is the function library of php, if I have to second guess its output?
-
<?php $quote=' Hi Php masters i need to know how to get multiple image urls in a text like this: blah blah blblbl <img class="image" src="showimage.php?i=47&w=4&t=scr&n=360907130665931"> bleh text text <img src="showimage.php?i=47&w=4&t=scr&n=360907130665932" align="center" whatever="whatever" > blah blah blblbh text .... actually i need to get this : showimage.php?i=47&w=4&t=scr&n=360907130665931 I\'ll really appreciate if anyone can quickly reply to this thanks'; header('Content-type: text/plain'); if(preg_match_all('/<img\s.*?src=\"(.*?)\".*?>/i',$quote,$matches)) print_r($matches); else echo 'no matches'; ?>
-
[SOLVED] how to stop script and display html
laffin replied to crouzilles's topic in PHP Coding Help
U can only break out early from functions (return) and loops (for/while) so either convert to function as anupam has done or use a do/while fake loop $name='laffin'; $pass=''; do { if(empty($name)) { $error='Name required'; break; } if(empty($password)) { $error='password required'; break; } } while(FALSE); if(isset($error)) echo 'We got an error'; else echo 'Success'; Since the expression in WHILE is always FALSE, this will make 1 pass loop, with break statements to exit the loop early -
<?php $base='./'; // Remember that this shud have the ending / $files = scandir($base); foreach($files as $key => $sub) { if(preg_match('/^\d*$/',$sub) && is_dir($sub)) // Only do folders with numbers only { $subfiles=scandir("{$base}{$sub}"); $count=0; foreach($subfiles as $sf) if(is_file($s2)) $count++; if($count<10) { $subfolder=$sub; break; } } } if(isset($subfolder)) echo "{$sub} is next available dir"; else echo "No available dir"; ?>
-
echo "<tr>"."\n".$r[0].$r[1]."<td>".kMGTB2($size2)."</td><td>".$r[3]."</td><td>".$r[4]."</td>".$r[5].$r[6]."\n"."</tr>"."\n"; print_r returns a string of the string/array sent to it. primarily for debugging. the use of print_r is redundant in this situation, as u know u are dealing with only strings from yer function.
-
Yes, I rely on filesize to always return a positive whole number, Otherwise I wud write my own instead of using the php function or that in speed calculations also return a whole positive number. Validation isnt necessary when u already know the bounds of a function. U know that filesize will never return < 0 or a float for a bytesize count, so u go with that. It wud be silly to write code like if(($fsize=filesize('about.txt'))==NULL || $fsize<0 || $fsize!=abs($fsize)) die('error'); because u want to validate the value first. anyways, a mix of my routine and one posted by Aexia results in this, its nice and does the job function ByteSize($size) { static $unit = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $size/=(pow(1024,($idx=floor(log($size)/log(1024))))); return number_format($size,2).$unit[$idx]; }
-
I prefer something quite a bit smaller <?php function ByteSize($size) { static $unit = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $idx=0; $mult=1; while($size>$mult*1024) { $idx++;$mult*=1024; } return number_format(($size/$mult),2).$unit[$idx]; } $val=123456789; echo "{$val} = ".ByteSize($val); ?> Although yers has a lot of validation, I rarely ever use validation in these routines just because they are delegated by other routines, filesize/speed. Note: I do love that routine by Axeia though, but rarely use sprintf in my coding as string expressions are already built into php. So a mix of that and this would work well.
-
I built a discussion board. How do I manage time zones?
laffin replied to chantown's topic in PHP Coding Help
TimeZone by user Look at this post -
U require more than basic PHP. Looks like u will need CURL (too pass login info) / preg_match (to get the info from the page/scrape) but scraping pages in this fashion take time, so on a forum signature this can cause a bad situation. if a page/thread you become very active in, loads up. as each posting will perform the scrape (get page contents). Yer best bet is to see if the site owner can create a counter files, or who's online file for such use. Or to cache the results, and perform the scrape every once in awhile.
-
if it's specific, why not set yer errors to be specific as well. Use an array for yer errors,with the key index being the whre to place the error code and not shure why u need to redirect, I wud have the login only redirect on successful login. <?php start session(); if($_SERVER['REQUEST_METHOD']=='POST') { if(empty($_POST['username'])) { $error['username']="Required Field"; } elseif(empty($_POST['password'])) { $error['password']="Required Field"; } elseif(!preg_match('/[a-z]\w{4,}/i',$_POST['username'])) { $error['username']='Username invalid'; } if(!isset($error)) { // Code here to check user // example we use hardcoded, but normally sql connection and query goes here if(!($_POST['username']=='Laffin' && $_POST['password']=='password')) $error['general']="Invalid Login"; else { header('location: profile.php'); die(); } } } ?> <form enctype="multipart/form-data" method="post" action="login.php" name="login"> <fieldset> <?php if(isset($error['general'])) { ?> <span class="error"><b>Error: </b><?php echo $error['general']; ?></span><br /> <?php } ?> <legend>Login</legend> <label for="username">Username: </label> <input id="username" name="username" /> <?php if(isset($error['username'])) { ?> <span class="error"><b>Error: </b><?php echo $error['username']; ?></span> <?php } ?> <br /> <label for="password">Password: </label> <input id="password" name="password" type="password" /> <?php if(isset($error['password'])) { ?> <span class="error"><b>Error: </b><?php echo $error['password']; ?></span> <?php } ?> <br /> <input value="Login" type="submit" /> </fieldset> </form>
-
U have to start_session() before u can remove a session var
-
[SOLVED] select a substring between two characters
laffin replied to anatak's topic in PHP Coding Help
Yeah, regex is real good. Just takes time to learn tho. But once ya get the basics, man is it ever so helpful -
Use hidden fields with the ids. <input type="hidden" name="pic[0]" value="xxx"> or you can set the key element of the array <input type="radio" name="vote[xxx]" value="0">Option 1<br /> <input type="radio" name="vote[xxx]" value="1">Option 2<br /> <input type="radio" name="vote[xxx]" value="2">Option 2<br /> replace xxx with the pics id I think I wud use 2nd method as than ya can pull the information with foreach with the key element