Member Avatar

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="" > 
  <rdf:Description rdf:about=" 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...

Recommended Answers

All 4 Replies

An example based on this comment:

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

    $manifest = $xml->children('');
    $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.

Member Avatar

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

Member Avatar

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, learning, and sharing knowledge.