Member Avatar for vijiraghs

the following is my requirement:

There are thousands of RDF files in a folder in my local webserver. The following is the structure of each of the files.

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" > 
  <rdf:Description rdf:about="http://www.wordpress.com/blogs/introduction to RDF">
    <rdf:subject>introduction to RDF</rdf:subject>
    <rdf:object>vj</rdf:object>
    <rdf:value> formality</rdf:value>
    <rdf:value>intro</rdf:value>
  </rdf:Description>
</rdf:RDF>

The user will enter a keyword. I want to write a PHP program that will look into the
<rdf:value> fields in all the RDF files to see if the keyword given by the user and the value in <rdf:value> match. If there is a match, the program has to return the <rdf:object> field's value ( in this case, "vj" )


I have deployed wordpress locally in WAMP. The entire website is in PHP. I dont know PHP. So, a million thanks if anyone can provide me with the code.

Thanks in advance...

Recommended Answers

All 4 Replies

An example based on this comment: http://www.php.net/manual/en/ref.simplexml.php#66259

<?php
function display($in, $string) {
    if (file_exists($in)) {
        $xml = simplexml_load_file($in);
    } else {
        throw new Exception($in . " does not exist");
    }

    $manifest = $xml->children('http://www.w3.org/1999/02/22-rdf-syntax-ns');
    $a = '';
    foreach ($manifest->xpath('//rdf:value') as $value) {
	if(trim($value) == trim($string))
	{
		$a = $manifest->xpath('//rdf:object');
	}
    }

    # json used to remove SimpleXMLElement Object
    return json_decode(json_encode($a),true); 
}

$f = 'file.rdf';
$search = 'formality';
print_r(display($f,$search));
?>

Will give you this:

Array
(
    [0] => Array
        (
            [0] => vj
        )

)

You can improve it, just read the documentation, bye.

Member Avatar for vijiraghs

Thanks a lot.. Will try it out and post the result.

Member Avatar for vijiraghs

There are a number of files in a folder in my system. I want to parse all those files. How can i get the file names and send them as a parameter to the function??

Is there a way to put all these file names in an array and send it to the function??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.