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.

    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:value> formality</rdf:value>

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...

Edited by vijiraghs: n/a

6 Years
Discussion Span
Last Post by cereal

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

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';

Will give you this:

    [0] => Array
            [0] => vj


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


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??

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.