Page 1 of 1

is_a() function with hyperlink

Posted: Sat Apr 10, 2010 2:51 am
by mr.aizek
Hi. My name is Isaac.

My code is:

function getNodeTypeName($node) {
if (is_a($node, "BlankNode"))
return '';

elseif (is_a($node, 'Literal'))
return '';

elseif (is_a($node, 'Resource'))
return "<a href='/$node'>";


else {
if (RDFUtil::getNamespace($node) == RDF_NAMESPACE_URI || RDFUtil::getNamespace($node) == RDF_SCHEMA_URI || RDFUtil::getNamespace($node) == OWL_URI)
return '';}

return '';
}

........

Notice that my code:
elseif (is_a($node, 'Resource'))
return "<a href='/$node'>";


and the output link is:
http://localhost/Resource("http://202.1 ... -bar.jpg")

Can anyone help me how to make a link that directly point to http://202.185.70.191:8080/Monogenean/i ... al-bar.jpg
instead of the output above?

Really need help.

Thanks.

From Isaac. MALAYSIA.

Re: is_a() function with hyperlink

Posted: Sat Apr 10, 2010 3:02 am
by josh
Create a method. $node->url()

Re: is_a() function with hyperlink

Posted: Sat Apr 10, 2010 3:14 am
by mr.aizek
Hi josh.

Thanks for the reply.

I'm extremely new to PHP.

I'm actually looking at someone's source code and simply applied it to my web application.

How can i actually make a new method url() then?

And owh yes, the message error was: Fatal error: Call to undefined method Resource::url()

Thanks.

Isaac.

Re: is_a() function with hyperlink

Posted: Sat Apr 10, 2010 5:45 am
by josh
Here is an example of a basic class, with a method foo, with a paramater $p1, an instance variable $x; Calling the foo method with some inputs "concatenates" a string and outputs it.

Code: Select all

class Resource {
 var $x;

 function foo( $p1 ) {
  $this->x =1;
  echo 'hello world ' . $p1 . ' ' . $this->x;
 }
}

$node = new Resource();
$node->foo('test'); // hello world test1
I would modify your class to have a method called url() that can output the URL.

Here's the manual for objects. http://us2.php.net/manual/en/language.oop5.basic.php

Re: is_a() function with hyperlink

Posted: Sat Apr 10, 2010 7:00 am
by mr.aizek
Hi Josh.

Thank you so much for the code.

Anyway, while waiting for a reply from you or anybody, I've checked the source code package and I managed to solve my own problem.

I've changed:

function toString() {
return 'Resource("' . $this->uri .'")';
}

to:

function toString() {
return $this->uri;
}

instead.

Hmmmm.... Now my new problem this: instead of using <a href>, I need to make it as <img src> with <a href>.

I am actually a Bioinformatician from the University of Malaya, doing a research on semantic web search engine technologies using RAP (RDF API for PHP).

Thanks Josh.

Isaac Alfred Simbun,
Biodatabase & Informatics Architecture Laboratory (BIAL),
Bioinformatics Division,
Faculty of Science,
The University of Malaya,
Kuala Lumpur MALAYSIA.