0

Possible Duplicate:
RegEx match open tags except XHTML self-contained tags

Hello first of I would like to say I'm a beginner.

My problem is I'm developing a video site, the site pulls an xml from an other site, and saves the data in my database.

In the embed adds a:

<div style="margin:auto" align="center">-
embed here
</div>

And an achor with text upload free videos here.

Now I would like to remove these with preg replace but its not working.

function insertvids() {

        $url = "http://thesite/rss.xml";
        $data = simplexml_load_file($url, "SimpleXMLElement", LIBXML_NOCDATA);
        //print_r($data->channel->item);

        foreach ($data->channel->item as $r)
        {
          $title = $r->title; 
          $description = $r->description;
          $embed = $r->embed;
          $thumb = $r->image;
          $duration = $r->duration;

           $string = $r->embed;

           $replace = array();
           $replace[0] = '-<div style="margin:auto" align="center">-';
           $replace[1] = '-<a href="http://thesite.com" target="_blank">-';
           $replace[3] = '-Unlimited video upload for free.-';
           $replace[4] = '-</a></div>-';
            $replaceto = array();
            $replaceto[0] = ' ';
            $replaceto[1] = ' ';
            $replaceto[2] = ' ';
            $replaceto[3] = ' ';
            $replaceto[4] = ' ';


            preg_replace($replace, $replaceto, $string);

            $data = array(
              'title' => ''.$title.'', 
              'description' => ''.$description.'',
              'thumbnail' => ''.$thumb.'',
              'embed' => ''.$embed.'',
              'duration' => ''.$duration.'',
              'type' => 'slutload'
        );
            $this->db->insert('videos', $data);
            //print_r($data) . "<br>";
        }

    }

Was trying to figure out what im missing. If I run the script it does nothing, if I change the - to / it gives me and error that it's not valid.

Could someone please point out what I'm doing wrong?

Community
  • 1
  • 1
Side
  • 1,753
  • 9
  • 35
  • 64

1 Answers1

2

Preg_replace doesn't modify the parameters. It will only return an array or a string (according to the type of parameters).

Raveline
  • 2,660
  • 1
  • 24
  • 28