preg_replace help please

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
wvucouchburner
Forum Newbie
Posts: 3
Joined: Mon May 11, 2009 8:07 pm

preg_replace help please

Post by wvucouchburner »

sorry guys im a php noob and i need help with this little bit of code here:

Code: Select all

<?php
# Set Values
$my_file = 'mlb1.xml';
$new_value = check_input($_POST['url'], "Enter URL of stream");
# Get file contents
$xml = file_get_contents($my_file);
# Regex
$xml = preg_replace('<file>"(.*)"</file>', "file=\"$new_value\" /file", $xml);
# Write file out again
file_put_contents($my_file, $xml);
/* Functions we used */
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}
 
function show_error($myError)
{
?>
    <html>
    <body>
 
    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>
 
    </body>
    </html>
<?php
exit();
}
?>
 
This code takes a URL entered into an html form on another page and uses the value to overwrite a value in a separate xml document, i am having a bit of trouble with the preg_replace syntax trying to replace a value from inside <file></file> in the xml document with the new URL
If you guys could show me the way or correct me that would be great. also if you correct it and u run across any other errors please help me with those as well. thanks
Last edited by wvucouchburner on Tue May 12, 2009 11:12 am, edited 1 time in total.
wvucouchburner
Forum Newbie
Posts: 3
Joined: Mon May 11, 2009 8:07 pm

Re: preg_replace

Post by wvucouchburner »

also, at the part where it says "Enter URL of Stream" what exactly is supposed to be in that part of the code. that was what somebody else had told me to put there but it gives me an error reading: "Please correct the following error: Enter URL of stream" so im not sure what to make of it anymore :(
wvucouchburner
Forum Newbie
Posts: 3
Joined: Mon May 11, 2009 8:07 pm

Re: preg_replace help please

Post by wvucouchburner »

can anybody help me with this please? :)
Post Reply