chrispynic Posted October 4, 2008 Share Posted October 4, 2008 I'm loading an XML file to MySQL via a PHP script and need some help. In the XML file there is a node called "description" and I want to ignore part of the string (everything in parentheses) when loading it into the db. Example Value in XML File: <description>Radio City Music Hall (1260-6th Avenue , New York, NY, 10020) </description> My PHP file: $xml = simplexml_load_file('./tmp/file.xml'); foreach($xml as $node){ $sql = "INSERT INTO feed_data(source_feed ,url ,event_name ,event_venue ,price ,image_url,event_date,event_time) values ('".mysql_real_escape_string($node->programname)."','".mysql_real_escape_string($node->buyurl)."','".mysql_real_escape_string($node->name)."','".mysql_real_escape_string($node->description)."','".$node->price."','".mysql_real_escape_string($node->impressionurl)."',STR_TO_DATE('".$node->startdate."','%m/%d/%Y %r'),STR_TO_DATE('".$node->startdate."','%m/%d/%Y %r'))"; mysql_query($sql); echo mysql_error(); } mysql_close(); Any recommendations on how to do this within the current format? I've looked all over, but I'm a newbie and not really sure what I'm looking for.. Link to comment https://forums.phpfreaks.com/topic/127044-simple-xml-to-mysql-parse-question/ Share on other sites More sharing options...
chrispynic Posted October 4, 2008 Author Share Posted October 4, 2008 I'm kind of surprised no one responded to me on this - turns out it was pretty easy, so I'll put the solution here for future reference. I used preg_replace: $venue = preg_replace('(\(.*?\))', '', $node->description); and then loaded $venue into the db. Link to comment https://forums.phpfreaks.com/topic/127044-simple-xml-to-mysql-parse-question/#findComment-657278 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.