Modifying the Path Example.

In this example you will learn how to modify the corrupt Path.


Share on Google+Share on Google+

Modifying the Path Example.


In this example you will learn how to modify the corrupt Path.

Modifying the Path

In this example, you will learn how to modify the corrupted path using $outpath command in PHP. This command will modify the path in the correct way if it finds any error syntax in the defined path. The $outpath command will automatically correct by way of replacing the defined value in the program and if it finds it during compilation. After detecting the correct path it replaces the correct one with alteration path. Let's see the below example in steps:

First Begin the HTML tag, under it HTML Body and then begin the PHP tag.

Now, you set the output of the path with conditional statement using isset(); command. As we have set the path if (isset($_POST['posted'])). 

Define the outpath with special characters and characters, and print the old or new path.

End the PHP tag.

Now begin the form action and call the outpath code on the same page and print the value on the same page.

Set the dimension of output text box.

Close the form, close the HTML Body and tag.


// Setting output of the path
if (isset($_POST['posted'])) {
$path = $_POST['path'];
$outpath = ereg_replace("\.[\.]+", "", $path);
$outpath = ereg_replace("^[\/]+", "", $outpath);
$outpath = ereg_replace("^[A-Za-z][:\|][\/]?", "", $outpath);
echo "The old path is " . $path . " and the new path is " . $outpath;
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="posted" value="true">
Enter your file path for cleaning:
<input type="text" name="path" size="30">
<input type="submit" value="Clean">

In the out put it will show the new path by eliminating the above defined symbol.




Posted on: July 30, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles