Jump to content

greenheart

Members
  • Posts

    41
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

greenheart's Achievements

Member

Member (2/5)

0

Reputation

  1. Hello I am a php noobie and have a website I have designed all by myself. I'm adding a user login form in the corner of the page and the ability for logged in users to comment on my articles. I am using mysql_real_escape_string to prevent against sql injection attacks (have to load database records for user data and comment data) but is this sufficient/still the standard? I have heard of attacks that can get around this command, using other special characters I guess. Thanks
  2. Solved it. God knows why but the statement has to be in a for loop foreach($feeditem->getElementsByTagNameNS('uri','file') as $element){ $linkthumb = $element->getAttribute('data');} Even though there is only ONE instance of <media:file ... /> per feeditem. Anyway I don't understand the logic behind that one but eh it works.
  3. I tried that with $nodes = $feeditem->getElementsByTagNameNS('uri','file'); $linkthumb = $nodes->item(0)->getAttribute('data'); where uri is the uri relating to the media name space(NS) but it gives the error "Call to a member function getAttribute() on a non-object" Note that the media element is of the form <media ... /> not <media> </media> I think this is part of the problem, as I generally have no issue parsing for attibutes.
  4. Hello I have an api response in xml format with a series of items such as this: <item> <title>blah balh</title> <pubDate>Tue, 20 Oct 2009 </pubDate> <media:file date="today" data="example text string"/> </item> I want to use DOMDocument to get the attribute "data" from the tag "media:file". My attempt below doesn't work: $xmldoc = new DOMDocument(); $xmldoc->load('api response address'); foreach ($xmldoc->getElementsByTagName('item') as $feeditem) { $nodes = $feeditem->getElementsByTagName('media:file'); $answer = $nodes->item(0)->getAttribute('data'); } What am I doing wrong? Please help. Usually it works but I think it doesn't this time because the <media:file /> tag is a little different than normal (node length is zero I think and there is no text inside.
  5. Thanks everyone I figured it out. I used the strpos that thebadbad gives in his code and put it in my code and it works.
  6. Hello, I have tried with this and variants but no success preg_match_all('#src="(http://[^"]+)#', $value, $matches) $i=0; for ($i = 0; $i < 10; $i++){ preg_match_all('#pass#',$matches[i], $result) print_r($result) } The idea is stop once I have a match. Could you help me please?
  7. Here is my code which looks for addresses which start with ' src=" ' preg_match_all('#src="(http://[^"]+)#', $value, $matches) I want to modify this so that it only returns matches which contain the phrase "pass". So src="http://www.example.com/blah/pass/edu" would be picked up. Can someone kindly tell me how to do this? Thank you so much.
  8. Thanks just what I was looking for.
  9. Hello I have an array of data. How do I reverse the order of the elements? So if Array[0]= test, Array[1]=new, Array[2]=done how do I reverse the elements so that Array[0]=done, Array[2]=test etc. The arrays in question are large and full of parsed data that changes.
  10. Anyone?
  11. Sorry here's the code chunk: if (!empty($feeditem->getElementsByTagName('extra'))){ $extra = $feeditem->getElementsByTagName('extra'); $extraname = $extra->item(0)->getAttribute('name'); } Code works fine if the DOMdocument has an 'extra' element in each of the $feeditems. Your advice is really appreciated.
  12. SORRY I was wrong, I haven't got it working. basically when 'extra' isn't detected by getelementsbetagname I get a non-object error trying Tenyon's and "Can't use method return value in write contex" with yours Chronister. So I need the if statement to specify that it isn't a non-object, I think?
  13. Yes Chronister I meant foreach. I tried your code and it gave an error but thanks for trying. Tenyon yours worked so thanks. Prob solved.
  14. Hello, I am parsing an xml file from an API which I have converted into a DOMDocument in php. This is mostly fine but one problem I have is when I do this: $feeditem->getElementsByTagName('extra'); as part of a forall statment and the element extra doesn't exist in one of the feeditems I am iterating through in the forall condition then I get an error. I think I need some kind of statment like: if ($feeditem->getElementsByTagName('extra') ISN'T NULL) But don't know how to formulate it. Please help. Thanks.
  15. Yes! Looked it up on google and cron is exactly what I was looking for. I found some examples which I can adapt. Cheers.
×
×
  • 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.