laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
On/Off Status images usually require information on getting the status of the user. U may want to check ICQ/MSN/AIM/Yahoo protocols. or create yer own client to pass info to a page (Like some DynDNS clients do, to get an updated ip address) Once ya got the method of On/Off Detection, than its just a matter of following post #2 in this thread. There is no real magic to this, just some thought beforehand
-
Just some updated code <?php header('Content-type: text/plain'); $line="this is a sample website http not working while http://www.google.com shud work. Now a more complicated example http://www.google.com/search?q=preg_replace secure connection https://docs.google.com http://www.php.net/ on a newline mailto links mailto:[email protected] ftp://yoursite.com telnet:myfunky.bbs"; function CutName($var,$len=40) { return strlen($var)>$len?(substr($var,0,(($len-3)/2)).'...'.substr($var,(($len-3)/2)-$len)):$var; } function prlinks($matches) { return '<a class="link" href="'. $matches[1] .'" target="_blank">'. CutName($matches[4]) .'</a>'; } $pr = preg_replace_callback('@((https?|ftp|mailto|telnet):(//)?([^\s]{4,}))@i','prlinks',$line); echo "Preg Match\n"; echo "{$pr}\n"; ?>
-
I think something is wrong I get Some completely different results <?php header('Content-type: text/plain'); $line="this is a sample website http not working while http://www.google.com shud work. Now a more complicated example http://www.google.com/search?q=preg_replace secure connection https://docs.google.com"; function CutName($var,$len=40) { return ; } function prlinks($matches) { return '<a class="link" href="'. $matches[1] .'" target="_blank">'. (strlen($matches[1])>20?(substr($matches[1],0,17).'...'):$matches[1]) .'</a>'; } $loops=500; $at=0; for($i=0;$i<$loops;$i++) { $st=microtime(TRUE); $pr = preg_replace_callback('@(https?://[^\s]*)@i','prlinks',$line); $at+=(microtime(TRUE)-$st); } $at/=$loops; $at=number_format($at,6); echo "Preg Match (Avg time = {$at} secs)\n"; echo "{$pr}\n"; $at=0; for($i=0;$i<$loops;$i++) { $st=microtime(TRUE); $parts = explode(' ', $line); foreach ($parts as $key => $part) { if (strpos($part, 'http') === 0 && strlen($part) > 39) { $parts[$key] = '<a class="link" href="' . $part . '" target="_blank">' . substr($part, 0, 10) . '...' . substr($part, -4, 4) . '</a>'; } } $ss=implode(' ',$parts); $at+=(microtime(TRUE)-$st); } $at/=$loops; $at=number_format($at,6); echo "\nSubstr (Avg time = {$at} secs)\n"; echo "{$ss}\n"; ?> Result Looks like something went sour on yer code, so time to go back and debug, and make yer code more complex.
-
The reason I kept it as different functions, not to make it messy, but to add more granularity to the functions... Having the CutName as its own function, allows u to use it elsewhere besides the links routine. So I dun see where Messy comes from? I used the fulll schema of http:// so it grabs full urls, instead of of someome saying just http how hard is it to add https thats simple for me $pr = preg_replace_callback('@(https?://[^\s]*)@i','prlinks',$line); Now how hard is it for the strpos routine u have? complex pattern matching is best for preg, strpos/substr will just add a lot more code. learn the basics of regex, it may take some time, but its well worth it.... So u should look at the difference between both codes again, to me the preg is a lot cleaner than the strpos method.
-
Wrote up some more code <?php header('Content-type: text/plain'); $line="this is a sample website http not working while http://www.google.com shud work. Now a more complicated example http://www.google.com/search?q=preg_replace"; function CutName($var,$len=40) { return strlen($var)>$len?(substr($var,0,$len-3).'...'):$var; } function prlinks($matches) { return '<a class="link" href="'. $matches[1] .'" target="_blank">'. CutName($matches[1]) .'</a>'; } $pr = preg_replace_callback('@(http://[^\s]*)@i','prlinks',$line); echo "Preg Match\n"; echo "{$pr}\n"; ?> Theres my entry :-) preg match is pretty flexible, it shud be faster or just as fast as a comparable strpos/substr/implode/explode routine...
-
count dusn care if the firstt key index is 0, it cud be 'a' count just returns the number of elements in an array. I think u meant, Dun rely on count as an key index indicator. u can use foreach in this matter. with the '$key => $name' portion which will cycle count()-1 times pretty shure u can also renumber the array with some array funtion....
-
html portion <input type="text" name="tbox[]"> <input type="text" name="tbox[]"> php portion $tbox=$_POST['tbox'] html portion the important thing is the name field add the array designator with no value (unless they key position dependent; name=tbox[0] address=tbox[1]) php portion just the name of the array is needed, php will assign the key index automatically if [] is used.
-
I wudda opted for preg_replace or a simpler substr system. I went with a preg_replace system and got this. <?php $line="this is a sample website http not working while http://www.google.com shud work. Now a more complicated example http://www.google.com/search?q=preg_replace"; $pr = preg_replace('@(http://([^\s?/]*)[^\s]*)@i','<a class="link" href="\1" target="blank">\2</a>',$line); header('Content-type: text/plain'); echo "{$pr}\n"; ?> but I belive a substr system wud be a lot faster. But this is simple and works nice output was
-
[SOLVED] SQLite, LIKE vs regular expression?
laffin replied to Axeia's topic in Other RDBMS and SQL dialects
just a thought the search query can contain up to1-6 keywords as u say so not shure the above query is wut yer looking for. as that would result in a search pattern where all keywords must be in a specific sequence. so maybe if yer keywords are in an array. I checked (REGEXP) in SQLITE is user defined, otherwise it returns an error. but if u need to do it in sqlite maybe using LIKE and ANDS will work than came up with this code, prolly some optimization is in due order. but it generates the LIKE as expected <?php $keywords=array("open","file"); function sqlesc($var,$quote=TRUE) { return is_int($var)?$var:(is_string($var)?(($quote?"'":'').sqlite_escape_string($var).($quote?"'":'')):FALSE); } function sqllike(&$var,$key,$param) { $var= "{$param} LIKE '%".sqlesc($var,FALSE)."%'"; } $param="filename"; array_walk($keywords,'sqllike',$param); $like=implode(' AND ',$keywords); echo $like; ?> -
[SOLVED] SQLite, LIKE vs regular expression?
laffin replied to Axeia's topic in Other RDBMS and SQL dialects
Just wondering if yer looking for BOTH OPEN and FILE, couldnt u use LIKE like: SELECT * FROM File WHERE downloaded IS NULL AND filename LIKE '%Open%File%'; -
Let me say, Holy.....l Thats a big script a lot of redundancy, which could have been solved with an array of values <?php $formvars = array( 'Personal' => array( array('Name',true,'Name'), array('Date',true,'Date'), array('DOB',true,'DOB'), array('Age',true,'Age'), array('Weight',true,'Weight') ), 'Current Medications' => array( array('CurrentMed1',false,'#1'), array('CurrentMed2',false,'#2'), array('CurrentMed3',false,'#3'), array('CurrentMed4',false,'#4'), array('CurrentMed5',false,'#5'), array('CurrentMed6',false,'#6'), array('CurrentMed7',false,'#7'), array('CurrentMed8',false,'#8'), array('CurrentMed9',false,'#9'), array('CurrentMed10',false,'#10'), array('CurrentMed11',false,'#11') ), 'Medication Allergies' => array( array('MedicationAllergies1',false,'#1'), array('MedicationAllergies2',false,'#2'), array('MedicationAllergies3',false,'#3'), array('MedicationAllergies4',false,'#4') ), ); $fail=false; foreach($formvars as $section=>$items) { $list=array(); foreach($items as $item) { if($item[1] && (!isset($_POST[$item[0]]) || empty($_POST[$item[0]])) { $fail=true; $error="'{$item[0]}' is required"; break; } if(isset($_POST[$item[0]]) && !empty($_POST[$item[0]]) $list[]="{$item[2]}: " .addslashes($_POST[$item[0]]); } if($fail==false) break; if(!empty($list)) { $body.="{$section}:\n" . implode("\n\t",$list) . "\n\n"; } } if($fail) { die("Error: {$error}"); } ?> This should put each var into its own section like Personal: Name: Laffin Date: 4/30/09 and skip sections and items that are empty although I would have suggested using arrays for some of them form vars, such as Current Medication. But that ya can do later. This was its pretty easy adding new variables to your form and processing is a breeze the arrays are in format 'Section Name' => array( array('POST_VAR',Required,'Header Name (used in body of message)') ) Okay that nuff for me
-
Yeah, it does come in handy, especially when yer looking at other ppls code proper indentation, leads to finding them missing {} which is a common problem
-
Well u need the images of the numbers I came up with this code <?php // Get and update our counter $counter=(file_exists('counter.txt') && (($counter=file_get_contents('counter.txt'))>0))?$counter+1:1; file_put_contents('counter.txt',$counter); // Max Numbers to appear on counter define('MAX_NUMBERS',3); // Pad Counter with 0's $counter=substr(str_repeat('0',MAX_NUMBERS).$counter,-MAX_NUMBERS); // Get Number Images Attributes (Width & Height) $iinfo=getimagesize('pics/0.gif'); $cw=$iinfo[0]; $ch=$iinfo[1]; // Calculate Max Width $iw=$cw*MAX_NUMBERS; // Create image canvas for counter $ci=imagecreate($iw,$ch); // Loop to get image of each digit for($i=0;$i<MAX_NUMBERS;$i++) { // Grab Next Number in $counter $num=substr($counter,$i,1); // If Number use number image otherwise blank $num=ctype_digit($num)?$num:'blank'; // Do We have the image already? if(!isset($images[$num])) // No, Load the image $images[$num] = imagecreatefromgif("pics/{$num}.gif"); // Place image in correct place on new counter image imagecopy($ci,$images[$num],$i*$cw,0,0,0,$cw,$ch); } // tell browser we displaying a gif header('Content-type: image/gif'); // Show our image imagegif($ci); ?> See nothing to it, just make shure gd2 extension is loaded. Well up to u to take this and make it better
-
U need to use an external data reference for the credit storage, either flat file or db (mysql or similar)
-
if yer using IM, a good place to share code is pastebin As ppl can join in and update the code snippets. its another great tool, besides Beautify yer Code Cuz no one likes messy code (It hurts brains)
-
echoing values from database with gradient color.
laffin replied to seany123's topic in PHP Coding Help
U shud be able to do it in php. Question is how is the gradiant supposed to appear. u can use some inline .css to make user selectable gradiants which would be good for a background. or if ya want to be a real pain and do individual characters from a string (font text gradiant). -
[SOLVED] Integrating php code with HTML
laffin replied to mad wet squirrel's topic in PHP Coding Help
That sounds too simple Prismatic, we demand a complicated anwer. LOL Yep, that simple -
if yer login systen doesnt need a login successful page than no, a redirect isnt needed on the login successful page u can inlcude the members page (again, if nothing is outputted) sumfin like if(!$loggedin) die('Invalid Login'); include('members.php'); simple and effective
-
1) Dun think its xhtml or css, as they are 100's of ways of doing things with programming. if u know some concepts of programming (basic, c, lua) than its just a matter of learning syntax, functions, structure (which can be grasped from tons of scripts already available (I started with tbdev.net Open Source torrent tracker). if you dunno anything about programming, than ya want to use them tutorials, some do offer good projects (I love projects where I get to see something working). like guest books, counters (simple projects, dun jump into cms's just yet). Than just continue to advance into other projects/tutorials. And if ya run into problems, plenty of ppl here at phpfreaks to give ya a ideas methods, sample code. Yeah, phpfreaks is one of my favorite places, I learn some new things which is good, which is one of reasons I stay... And dun forget a good book on php functions, or just use php.net to lookup the various functions (It surprises me the functions in php)
-
[SOLVED] PHP: Session 2-Dimensional Array - Track Viewed Products
laffin replied to ticallian's topic in PHP Coding Help
Looks okay, whats the problem? -
Referrer checking, hiding actual file locations
laffin replied to DaveLinger's topic in PHP Coding Help
But why even use that? Use .htaccess to redirect .mp3 extensions to a php script or if yer server is PATH_INFO enabled, ya can do the same without .htaccess put the mp3's into an off-web folder, so they cant directly link to the mp3. and use a session cookie to track that its a valid logged in user. have yer script check the session, send the proper header, and readfile boom yer done. can prolly make a small mp3 with a message 'Mp3's brought to you by xxx.... Please no hotlinking' -
write and append filename to text file if not exist
laffin replied to acctman's topic in PHP Coding Help
shud be rread wwrite append. u can add a + which sets it as both read/write. r read only, file pointer at start r+ read/write, file pointer at start w write (kill original file), file pointer at start w+ read/write (kill original file), file pointer at start a append, file pointer at end a+ append/read, file pointer at end and ya can add to the aboce to put it in binary mode (no cr/lf translation) -
I wudn use cookie loggedin=1 just because anyone can edit the cookie than and mess with the script Why add more cookied, when u can put the expires on the loggedin cookie instead. use the username/pass with md5(). to generate a key. which is much harder to fake. And why the mix of cookies and sessions.