www.webdeveloper.com
Results 1 to 11 of 11

Thread: Code works locally, but not online.

  1. #1
    Join Date
    Aug 2006
    Posts
    87

    Code works locally, but not online.

    Hi peopole.

    I have some php code that won't execute properly online, however it works perfectly on my local test server.

    Can anyone help me?

    this is the code...

    Code:
    $text = '<div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" type="application/x-shockwave-flash" width="425" height="335" allowfullscreen="true"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x2ln7h_gagner-de-l-argent-en-restant-chez_videogames">GAGNER DE L ARGENT EN RESTANT CHEZ SOI</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/zdax6">zdax6</a></i></div>';
    
    echo preg_replace("/.*?value=\"(.*?)\".*/si", "$1", $text);

    It basically takes the line "http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" out of that code with regular expressions.

    It works locally on my test server, but when i put it online it doesn't seem to be having any effect on it.

    PLEASE SOMEONE HELP! IT WOULD BE MUCH APPRECIATED!!

  2. #2

    resolved

    Hi rapidz,
    I really don't understand what $1 is in your code. Variables can not start with number as I know.
    If you are trying to replace the link try to use :
    PHP Code:
    <?php

    $replace 
    'http://www.dailymotion.com/swf/NEWNEWNEW';
    $text '<div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" type="application/x-shockwave-flash" width="425" height="335" allowfullscreen="true"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x2ln7h_gagner-de-l-argent-en-restant-chez_videogames">GAGNER DE L ARGENT EN RESTANT CHEZ SOI</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/zdax6">zdax6</a></i></div>';

    echo 
    preg_replace("/.*?value=\"(.*?)\".*/si""$replace"$text); 

    ?>

    Hope it helps,
    Mihai

  3. #3
    Join Date
    Aug 2006
    Posts
    87
    what i'm trying to do is take the "http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" out of all that text and store it in a variable.

    It works fine locally, but not on the web...

  4. #4

    resolved

    I'm not sure where do you get that $text content from ?
    I use a function to get the contents for text or cURL operations.

    This code should work online, upload it if it's not working and post the link for exact code:

    PHP Code:
    <?php
    function get_middle($source$beginning$ending$init_pos) {
        
    $beginning_pos strpos($source$beginning$init_pos);
        
    $middle_pos $beginning_pos strlen($beginning);
        
    $ending_pos strpos($source$ending$beginning_pos 1);
        
    $middle substr($source$middle_pos$ending_pos $middle_pos);
        return 
    $middle;
    }

    $text '<div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" type="application/x-shockwave-flash" width="425" height="335" allowfullscreen="true"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x2ln7h_gagner-de-l-argent-en-restant-chez_videogames">GAGNER DE L ARGENT EN RESTANT CHEZ SOI</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/zdax6">zdax6</a></i></div>';

    // assign to $get
    $get get_middle($text'value="http:''"></param'0);

    echo 
    $get

    ?>
    Or what errors you get ?
    Give more details pls so I may help

  5. #5
    Join Date
    Aug 2006
    Posts
    87
    surely thats a lot of code for what i want to do, isn't there an easier way??

    here's my original topic if this helps...

    http://www.webdeveloper.com/forum/sh...452#post782452

  6. #6
    I'm not sure, I always use that function to get content. You have it assigned to $get .. just copy paste you don't need to modify anything.

    Thanks

  7. #7
    Join Date
    Aug 2006
    Posts
    87
    it outputs this...

    width=\"425\" height=\"335\">

  8. #8
    Quote Originally Posted by rapidz
    it outputs this...

    width=\"425\" height=\"335\">

    Do you have the exact $test content ? where you test ?
    If not :
    $get = get_middle($text, 'value="http:', '"></param', 0);

    Replace the bold text with exact tags between which the content will output.

    if you want to get : cat from next string "<sdhjcgbsd?jcat;tya"
    USE:
    $get = get_middle($text, 'd?j', ';ty', 0);

    I hope you got how function works, it worked for me all the times, it should work fine for you as well.

    Hope it helps

  9. #9
    Join Date
    Aug 2006
    Posts
    87
    still doesn't work, even when i do that.

    The original code i posted works locally, but not online - i just cannot understand why. its insane.

  10. #10
    Can you create a file.php with my 1st code , upload it and give me the link. It should work 100% online.
    If you have a different code, I can help only if I see the entire code.

  11. #11
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    PHP Code:
    $text '<div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" type="application/x-shockwave-flash" width="425" height="335" allowfullscreen="true"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x2ln7h_gagner-de-l-argent-en-restant-chez_videogames">GAGNER DE L ARGENT EN RESTANT CHEZ SOI</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/zdax6">zdax6</a></i></div>';

    echo 
    preg_replace("/.*?value=\"(.*?)\".*/si""\1"$text); 
    Ripe, $1 is an internal value used in preg, it means use the first match as the replacement string.

    Threw me off by making a new post, glad I spotted it

    Try changing the $1 for a \1 instead, I know some web servers conform to different preg values.

    If that is still no help then can you upload the following to your server and give us a link?

    PHP Code:
    <?php
    $text 
    '<div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/6TMx6A6bDKSlyikB7" type="application/x-shockwave-flash" width="425" height="335" allowfullscreen="true"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x2ln7h_gagner-de-l-argent-en-restant-chez_videogames">GAGNER DE L ARGENT EN RESTANT CHEZ SOI</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/zdax6">zdax6</a></i></div>';

    var_dump($text);
    ?>
    Last edited by MrCoder; 07-25-2007 at 02:22 PM.
    Quote Originally Posted by temp.user123
    You know... You're not so smart. Do you need me to educate you?
    If you say, "please," (and do so, nicely) then I will show you where you're dead wrong.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles