Jump to content

Variable + String


underv3

Recommended Posts

How would I put a variable and a string together. For example if I had $test and I wanted to add "random" after the variable how would I go about that?

 

Real life example would be in a search engine when making a request and I want to add a certain keyword that will always come after what is searched.

 

Thanks

Link to comment
Share on other sites

Yes, thanks, but there is my other post http://www.phpfreaks.com/forums/index.php/topic,212118.0.html

 

This issue is still troubling me, if you could help out that would be great.

 

Thanks

 

I am working on a program that can get bio's for music artists and i came across this

http://www.davidcraddock.net/2008/06/18/scraping-artists-bios-off-of-wikipedia/

It seems like a good start but when i attempted to run it I got some errors leading me to believe that the yahoo API implementation was outdated. Working from this i then added the "echo grabwiki(Rihanna);" as a test just to see if it would work. It looks as though everything works until it gets to "$b = $s->xpath("//p:abstract

[xml:lang='en']");". I have no idea what to do with this line of code. I've been playing around with the code and searching google but I can't seem to make it work.

The errors:
Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: Undefined namespace prefix in /home/jamesad/public_html/searchbio.php on line 16

Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: xmlXPathEval: evaluation failed in /home/jamesad/public_html/searchbio.php on line 16

<?php
function grabwiki($band){
    $band = urlencode($band);
    $yahoourl = 'http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=%22$band%22%20music&site=wikipedia.org';
    $x = file_get_contents($yahoourl);
    $s = new SimpleXMLElement($x);
    $ar = split('/',$s->Result->Url);
    if($ar[2] == 'en.wikipedia.org'){
      $wikikey = $ar[4]; // more than likely to be the wikipedia page
    }else{
      return ""; // nothing on wikipediea
    }
    $url = "http://dbpedia.org/data/$wikikey";
    $x = file_get_contents($url);
    $s = new SimpleXMLElement($x);
    $b = $s->xpath("//p:abstract[xml:lang='en']");
     return $b[0];
}
// if ($band == false) {
//    die("No Information Available");
//}
echo grabwiki(Rihanna);
?>

 

If someone has any ideas I would be open to any suggestions.

Thanks!  :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.