The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. October 14, 2019, 07:21:39 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Coding with efficiency in php  (Read 2929 times)
ekibastos
Rookie
**
Offline Offline

Posts: 38


View Profile
« on: January 26, 2009, 07:09:32 AM »

Alright I wrote this function a long time ago in a different language and i just translated it into php , it works and provides basically the same functionality but not being so fluent at php I thought I would throw this up here and see if you people have some suggestions or criticisms as to how the 'information between double quotes' on a strvar in php could be retrieved more efficiently or correctly.

Code:
function WhatsInBetweenTheDoubleQuotes($inputstr)
{
   $restofstring = $inputstr;
   $firstquote = strpos($inputstr, chr(34) );
   if ($firstquote){
   
   $restofstring2 = substr($restofstring, $firstquote+1, strlen($restofstring));
     
   $secondquote = strpos($restofstring2, chr(34));
     
   if (!$secondquote){
        //result := '**ERROR** UNTERMINATED QUOTATION';
        //exit;
   }
    //
    $final = substr($restofstring2, 0, $secondquote);
     
   }
   
   return $final;
}

« Last Edit: February 12, 2009, 09:25:57 PM by perkiset » Logged

<quote nutballs>
Apple is that hot chick that gives you lots of sex but is a total bitch with a horrible abusive temper.
</quote>
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #1 on: January 26, 2009, 07:12:55 AM »

um

Code:
preg_match('/\"(.+?)\"/', $inputStr, $matches);
$inBetwixtTheQuotes = $matches[1];

What do I win?
Logged

hai
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: January 26, 2009, 08:04:23 AM »

 ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
netmktg
Rookie
**
Offline Offline

Posts: 37



View Profile
« Reply #3 on: January 26, 2009, 10:55:37 AM »

um

Code:
preg_match('/\"(.+?)\"/', $inputStr, $matches);
$inBetwixtTheQuotes = $matches[1];

What do I win?


...or this, which matches both double/single quotes...

Code:
preg_match('/(\"|\')([^\'\"]+?)\1/', $inputStr, $matches);
$inBetwixtTheQuotes = $matches[2];
Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #4 on: January 26, 2009, 11:10:07 AM »

You're still missing grave quotes though  Grin
Logged

hai
ekibastos
Rookie
**
Offline Offline

Posts: 38


View Profile
« Reply #5 on: January 27, 2009, 04:54:12 AM »

um

Code:
preg_match('/\"(.+?)\"/', $inputStr, $matches);
$inBetwixtTheQuotes = $matches[1];

What do I win?

 ROFLMAO

Thanks, and wow!  My brain hurts now.
Logged

<quote nutballs>
Apple is that hot chick that gives you lots of sex but is a total bitch with a horrible abusive temper.
</quote>
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #6 on: January 27, 2009, 09:05:34 AM »

As I recall, Delphi did not have support for Regex, so you'd not be too big on them.

They are the shiz. Google for Jan Goyvaerts book & site, Regular Expressions, the Complete Tutorial. I've referenced it here before as well.

It's a need-to-know.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
netmktg
Rookie
**
Offline Offline

Posts: 37



View Profile
« Reply #7 on: January 27, 2009, 01:46:52 PM »

Google for Jan Goyvaerts book & site, Regular Expressions, the Complete Tutorial. I've referenced it here before as well.

Jan Goyvaerts rocks...he's the one who developed EditPad Pro... with built in Regex support & Syntax highlighting and a helluva lot more features that I would want in a Text editor. I've tested & learnt all my Regex in Editpad... been using it for over 4years. I still code PHP in Editpad... it's my "visual studio"  Nerd
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #8 on: January 27, 2009, 01:53:11 PM »

Right on - his book essentially changed my text parsing world. Although I have no desire to be *so very* dedicated to a single programmatic discipline, I admire those that do.

And they sure do help Wink
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!