PHP SUBSTRING

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rajaboys
Forum Newbie
Posts: 5
Joined: Wed Dec 24, 2008 7:13 am

PHP SUBSTRING

Post by rajaboys »

I have stored db URL like this ../../images/aprilfoolcards/lovefoolsday.gif, ../../images/navratri/navratri1.gif

want to know how to get category like aprilfoolcards, navratri in PHP.


Regards
Raja
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: PHP SUBSTRING

Post by papa »

User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: PHP SUBSTRING

Post by papa »

Code: Select all

 
<?php
 
//$subject = "../../images/aprilfoolcards/lovefoolsday.gif";
$subject = "../../images/navratri/navratri1.gif";
$pattern = '#\.\./\.\./([^/]+)/([^/]+)/([^/]+)#';
 
preg_match($pattern, $subject, $matches);
print_r($matches);
 
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHP SUBSTRING

Post by josh »

Store the string how you need it to be retreived, instead of storing the URL. You can generate the URL on each page view.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: PHP SUBSTRING

Post by php_east »

just use explode ('/',$url);
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: PHP SUBSTRING

Post by divito »

A little more clarification would be nice.
Post Reply