Closed Thread Icon

Topic awaiting preservation: regexp help please. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12471" title="Pages that link to Topic awaiting preservation: regexp help please. (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: regexp help please. <span class="small">(Page 1 of 1)</span>\

 
GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-13-2002 16:04

how do i get the extension of a file which i have saved as string. so:

"blabla.html" returns "html"
"pic.jpg" returns "jpg"

edit: im talking php.



[This message has been edited by GRUMBLE (edited 10-13-2002).]

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 10-13-2002 18:06

No need for regular expressions...

$filename = "image.gif";
$ext = strtolower(substr(strrchr($filename, "."), 1));


GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-13-2002 18:15

hooray! it works!

thanks max!

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-14-2002 15:26

another string related question.

say i get my uri with $REQUEST_URI:

"/blabla/prototyp/de/heiho.php?xy=z"

and i wanna check if the string "/de/" is somewhere in that big string how do i do that?

thanks.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-14-2002 15:46

I'd probably use dirname() and then explode() it and check through the array but I'm sure mr.maX has a much more efficient way of doing it (I would have suggested exploded the file name too and checking for $filename_bits[1])

___________________
Emps

FAQs: Emperor

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-14-2002 16:16

it worked! thanks!

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-14-2002 18:25

OK cool - if people are going to be doing a lot splitting and playing with URLs they might be interested in this function:
http://www.php.net/parse-url

___________________
Emps

FAQs: Emperor

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-14-2002 19:02

wow. that's interesting too.
but i only need one small part of the url:

.../xyz/de/content/...

i need to check if its "de" or "en" in there.
the explode works fine for me.

thanks!

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-14-2002 20:23

GRUMBLE: I'm glad it helped

I threw a few more solutions at him over ICQ so I'll pass them on (the one's above seem fine for this problem but some may one day wander in looking for a variation on a theme):

Regular expressions:

Something like this would also work:

code:
if (preg_match ("/\bde\b/i", $url_path)) {

}



mod_rewwrite:

clean up the URLs and use something like this:

<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
/([0-9]+)/(de

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 10-15-2002 13:59

The following code is much more effective than using explode()...

$pos = strpos(getenv('REQUEST_URI'), '/de/');
if ($pos === false) { // <-- three '=' signs
&nbsp;&nbsp;&nbsp;&nbsp;// '/de/' doesn't exist
}

BTW You can easily modify if statement by adding '!' (not) operator if you want to check if '/de/' exists...


« BackwardsOnwards »

Show Forum Drop Down Menu