Solved

extract path from file path in php

Posted on 2011-03-25
8
417 Views
Last Modified: 2012-05-11
How can I extract the path from a path to a file in php?
The path could be either UNC or local path so either \ or /
0
Comment
Question by:NewtonianB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35220006
I putted this together,
let me know if this doenst work for you because of some other demands:

preg_match('#(.*)' . DIRECTORY_SEPARATOR . '.*$#', $_SERVER['SCRIPT_FILENAME'], $aMatch);
echo $aMatch[1];

Open in new window

0
 

Author Comment

by:NewtonianB
ID: 35220014
Thanks Rik and how would I find the directory seperator?
0
 
LVL 8

Assisted Solution

by:Rik-Legger
Rik-Legger earned 50 total points
ID: 35220021
You don't need to find it,
it is an PHP constant which is filled with the right seperator.
No need to find it out for yourselff.
Works out of the box :)
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:NewtonianB
ID: 35220038
Ah ok, I just tried but it gives me back the entire path
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35220044
Can you show me the result you get?
0
 
LVL 5

Accepted Solution

by:
tsmgeek earned 450 total points
ID: 35220047
0
 

Assisted Solution

by:NewtonianB
NewtonianB earned 0 total points
ID: 35220057
fantastic tsmgeek works in all my scenarios thanks
0
 

Author Closing Comment

by:NewtonianB
ID: 35252829
thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Make an array show the subkey and put it in a query 2 56
JSON decode 5 46
PHP-MSSQL 2016 connection requirements for Windows 2012 29 80
Can't find an open element in HTML 5 53
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question