473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

PHP Explode ...?

106 100+
I know this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /**
  3. code owner: Rahul Sinha
  4. contact : rahul@zimaudio.com/rahulazm@gmail.com
  5. **/
  6. $str='http://www.mysite.com/directory/page.php';
  7. $arr = explode("com/",$str);
  8. echo $arr[1]; // prints directory/page.php
  9.  
  10. ?>
But what I want is to get directory/page (without .php)
or http://www.mysite.com/directory/page

How can I achieve this?
Jul 16 '10 #1

✓ answered by Dormilich

if you know the file extension, use basename()

4 1587
Dormilich
8,658 Expert Mod 8TB
if you know the file extension, use basename()
Jul 17 '10 #2
londres9b
106 100+
Many Thanks!
Jul 17 '10 #3
There is also another way if you want:
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. /** 
  3. code owner: Rahul Sinha 
  4. contact : rahul@zimaudio.com/rahulazm@gmail.com 
  5. **/ 
  6. $str='http://www.mysite.com/directory/page.php'; 
  7. $arr = explode("com/",$str); 
  8. $arr = explode(".", $arr[1]);
  9. echo $arr[0];  
  10. ?> 
  11.  
Jul 19 '10 #4
londres9b
106 100+
That's exactly what I want.
Thank You.
Jul 19 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rob Gudgeon | last post by:
Hi Is it possible to explode a string into an array using more than one separator? I have database records that contain several values, mostly split by semi-colons but some older records are...
6
by: William Krick | last post by:
I have a string containing concatenated ascii "records" that are each terminated by '\n'. For testing purposes, I construct sample data like this... $mystring =...
4
by: Richard Lawrence | last post by:
Hi there, I'm having a problem with PHP which I'm not sure how to best solve. Here is the code: $fp = fopen("comments.txt", "r"); while(!feof($fp)) { $line = fgets($fp, 1024); list($key,...
12
by: frizzle | last post by:
Hi there, i have a site with fake folders & files. htaccess rewrites everything to index.php?vars now in index.php i decide what file to include with a switch/case statement. to define where...
5
by: FFMG | last post by:
Hi, I need the php equivalent of explode in one of my app. I read a very big file and "explode" each line to fill a structure. The reading of the file, 19Mb, (I will also need to streamline...
0
by: k04jg02 | last post by:
Python has a nifty operator that will take a container and pass its elements as function parameters. In Python you can make a list like so: x = Then you can say: f(*x)
4
by: Davide | last post by:
Hi All, I'm trying to use explode to separate the result of a textual file, but it explode me only the first row. the foo.txt is pippo pluto pluto pippo pippo pippo .... I use this script...
8
by: Jack | last post by:
I would like to Explode a string into an array that does not begin at 0 but I can't get it to work. For example: $MyInfo = array(1 =27,68,31,19,40); will result in $MyInfo = 27 ... $MyInfo = 40...
5
by: sathyashrayan | last post by:
Dear group, The function to be used as follows: $links = "http://www.campaignindia.in/feature/analysis"; $tag1 = '<div class=feature-wrapper>'; $tag2 = '<h1><a href'; $tag3 = "</a>"; $op =...
8
by: vinpkl | last post by:
hi all i want to use explode url for shotening my urls i have a url like http://localhost/vineet/products.php?dealer_id=12&category_id=2 This is my navigation php code that has url...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.