/    Sign up×
Community /Pin to ProfileBookmark

Remove characters in simplexml_load_file()

This php is for getting input that was entered by user in the textbox. The user will only input one keyword per line.After pressing “Run” button, those keywords will be saved in an array and written to the “test.txt”. And then it gets each keyword from the txt file and each keyword will be passed to simplexml_load_file() to be an object.

I know I can get each keyword correctly. But the problem is after going through simplexml_load_file(), the link becomes [url]http://localhost/xampp/example%3Cbr+%2F%3E.xml[/url]. My file is called example.xml, I don’t know how to remove “%3Cbr+%2F%3E”. I think it might be the problem of fwrite($fh, $newinfo[$i].”n”), when I write each word to file, I also include “n”. Anybody can help? Thanks.

Here is the warning message:
Warning: simplexml_load_file([url]http://localhost/xampp/example%3Cbr%20/%3E.xml[/url]) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:Program Fileshtdocsxamppnew.php on line 34

[code=html]<form action=”new.php” method=”POST”>
<textarea name=”keywords” cols=”70″ rows=”10″></textarea><br />
<input type=”submit” name=”run” value=”Run”>
</form>
[/code]

[code=php]
$items = $_POST[‘keywords’]; //store all keywords input in an array
$tobr = nl2br($items);
$tobr = str_replace(array(“rn”, “r”, “n”), “:”,$tobr); // separate each keyword in array
$newinfo = split(“:”, $tobr);

$filename = ‘test.txt’;
$fh = fopen($filename, ‘w’);
for ($i=0; $i<sizeof($newinfo); $i++) {
if ($filename)
fwrite($fh, $newinfo[$i].”n”);
}
fclose($fh);

$file = file(‘test.txt’);
foreach ($file as $content_hs) {

$url1 = “http://localhost/xampp/”;
$url2 = “.xml”;
$url = $url1.rtrim($content_hs).$url2;
$xml = simplexml_load_file($url);
}
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Small_Moon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...