Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Php error

  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Php error

    <?php
    $ads = array();
    $bannerAds = array();
    $bannerAdsTime = time();
    $lines = file($bannerAdsPath) or die();
    foreach ($lines as $line) {
    $line = chop($line);
    if (($line != '') && (preg_match('^#', $line))) {
    if (preg_match('^[A-Za-z0-9]+\|\|', $line)) {
    $ads[] = $line;
    } else {
    list ($key, $val) = explode('=', $line);
    $bannerAds[$key] = $val;
    }
    }
    }
    function writeads()
    {
    global $bannerAdsPath, $ads, $bannerAds;
    $data = fopen($bannerAdsPath, 'w') or die();
    flock($data, 2) or die();
    fputs($data, @join("\n", $ads)."\n");
    while (list ($key, $val) = each ($bannerAds)) {
    if (($key != '') && ($val != '')) {
    fputs($data, $key.'='.$val."\n");
    }
    }
    flock($data, 3);
    fclose($data);
    reset($bannerAds);
    }
    ?>

    WHEN I EXECUTE IT IT GIVES ME ERROR LIKE BELOW

    Warning: preg_match(): No ending delimiter '^' found in /home/u504401126/public_html/ads/ads.inc.php on line 8

    PLEASE HELP ME I AM NEW IN PHP

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    371
    Thanks
    0
    Thanked 20 Times in 20 Posts
    PCRE regex syntax: Delimiters. Adding a character before and after the pattern is used to separate the pattern from optional Pattern Modifiers.

    Code:
    '^[A-Za-z0-9]+\|\|'
    should be
    Code:
    '#^[A-Za-z0-9]+\|\|#'
    or you could use the case-insensitive modifier
    Code:
    '#^[a-z0-9]+\|\|#i'

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Quote Originally Posted by schleppel View Post
    should be
    Code:
    '#^[A-Za-z0-9]+\|\|#'
    This may work, however most of the time you'll see forward slashes rather than the pound sign used (at least I have). It doesn't really matter what symbol you use (that I know of and to an extent) just as long as they're the same in the beginning and end.
    A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.
    More info on delimiters can be found HERE

  • #4
    New Coder
    Join Date
    May 2009
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry ! did not solve my problem..still the same error message

  • #5
    New Coder
    Join Date
    May 2009
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    could not solved...gives same error

  • #6
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts
    You might need to recheck your regular expression, do you just need it to start with a pound sign? if so this should work: preg_match('/^#/', $line)


  •  

    Tags for this Thread

    Posting Permissions

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