SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP newbie needs help

    Well I'm a PHP newbie and I need some PHP help and if there are someone that can help me out with my dilemma I would become very happy

    I have a string in an array that is called $content[TheDesc] in this string I want to search for a specific pattern and pass it along to the function dopicencode().

    The pattern is [IMGCODE]string[/IMGCODE] (observe that the IMGCODE and /IMGCODE is enclosed in brackets inside the $content[TheDesc]). The string that is enclosed in [IMGCODE] and [/IMGCODE] I want to send along to the dopicencode() function.

    The result of the dopicencode() I want to return and use as a replacement of the whole [IMGCODE]string[/IMGCODE] pattern.

    Anyone that knows enough of PHP to help me out with this


    The code I tried and that failed in a major way is

    PHP Code:
    $imageTemp = array ("[IMGCODE]","[/IMGCODE]");
    $replaceTemp = array("","");
    $strTemp str_replace($imageTemp,dopicencode($replacetemp),$content[TheDesc]); 

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just a thought. Create this function ...

    PHP Code:
    function stripIMG ($data) {
      
    $temp str_replace ("[IMGCODE]","",$data);
      
    $temp .= str_replace ("[/IMGCODE]","",$data);
      return 
    $temp;

    ... and then use it like so ...
    PHP Code:
    $strTemp dopicencode (stripIMG ($content[TheDesc])); 
    I am curious about [TheDesc] though. I would be surprised if it would work like that. Shouldn't it be $content['TheDesc'] ??
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmmm will look into it and see if I can create something useful from it .

    Will be back later if I run into more problems

    Oh and thanks mate

  4. #4
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by siteguru
    I am curious about [TheDesc] though. I would be surprised if it would work like that. Shouldn't it be $content['TheDesc'] ??
    Hmmm well the $content[TheDesc] works on the other places I have used it so I hope it is the correct syntax

  5. #5
    SitePoint Guru okrogius's Avatar
    Join Date
    Mar 2002
    Location
    US
    Posts
    622
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Liquide


    Hmmm well the $content[TheDesc] works on the other places I have used it so I hope it is the correct syntax
    The correct syntax actually is $array['item'] , but it tends to work without quotes on most setups.

  6. #6
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW here is the dopicencode() function if that helps you out to see my problem.

    PHP Code:
    function dopicencode($pic_input){

        list(
    $pic_file$pic_ending$pic_width$pic_height$pic_align) = explode(":"$pic_input);
        
    $pic_Temp "<IMG SRC='Images/Content/".$pic_file."' HEIGHT='".$pic_height."' WIDTH='".$pic_width."' ALIGN='".$pic_align."'>";

        return 
    $pic_Temp;

    I need to replace the [IMGCODE]Image definitions[/IMGCODE] inside a long string of text. $content[TheDesc] is the 'Description' field in my MySql database and can include several diffrent of these [IMGCODE][/IMGCODE] tags. And I wanted an easy way to include dynamic images inside the system itself. The dopicencode() function will be remodelled later on to actually grab the image data froma database aswell.

  7. #7
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Example

    I need to post an example I think in order for you guys to be able to help me out I think

    the $content[TheDesc] can for example look like this.

    “The Hunt: Rise of Evil” is a d20 campaign setting by Mystic Eye Games. In this book you will be immersed into the dark world of Gothos. You will find a new and fantastic land where the dreams and nightmares of our sleeping Earth folk find their way into this mystical world.


    [IMGCODE]"Ithganin-colorweb-small.jpg::200:278:right"[/IMGCODE]This unique campaign setting will give you new rules, kingdoms, classes, races, magic, and much more. Play in our world or simply apply all that you find here to any d20 game.


    Become a Child of the Waking Dream and join the hunt today!
    I then want the output to become:

    “The Hunt: Rise of Evil” is a d20 campaign setting by Mystic Eye Games. In this book you will be immersed into the dark world of Gothos. You will find a new and fantastic land where the dreams and nightmares of our sleeping Earth folk find their way into this mystical world.


    <IMG SRC='Images/Content/Ithganin-colorweb-small.jpg' WIDTH='200' HEIGHT='278' ALIGN='right'>This unique campaign setting will give you new rules, kingdoms, classes, races, magic, and much more. Play in our world or simply apply all that you find here to any d20 game.


    Become a Child of the Waking Dream and join the hunt today!
    You think you can solve this for me

  8. #8
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, this is untested, but if it works it will replace strings formatted with "filename:width:height:alignment".

    PHP Code:
    function doPicEncode($data)
    {
        
    $str preg_replace"#\[imgcode\](.+?)\[/imgcode\]#ie"getImgData('\\1'), $data );
        
    $img_data getImgData($str);
        
        
    $final preg_replace"#\[imgcode\](.+?)\[/imgcode\]#ie""<img src='{$img_data[0]}' width='{$img_data[1]}' height='{$img_data[2]}' align='{$img_data[3}' />"$data );

        return 
    $final;
    }

    function 
    getImgData($data)
    {
        
    $img_data explode(':'$data);
        
        return 
    $img_data;

    Unfortunatly it doesnt check to ensure all the attributes are contained within the string. So watch out for that.
    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  9. #9
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Phil.Roberts
    Okay, this is untested, but if it works it will replace strings formatted with "filename:width:height:alignment".

    Unfortunatly it doesnt check to ensure all the attributes are contained within the string. So watch out for that.
    The function that checks for all the data is done when you input the data so that I have solved already .

    But thanks for the heads up and tips!

  10. #10
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got error message:
    Parse error: parse error in /home/huntroec/public_html/Includes/functions.php(45) : regexp code on line 1

    Fatal error: Failed evaluating code: in /home/huntroec/public_html/Includes/functions.php on line 45


    PHP Code:
    //40 function doPicEncode($data)
    //41 {
    //42     $str = preg_replace( "#[imgcode](.+?)[/imgcode]#ie", getImgData('\1'), $data );
    //43     $img_data = getImgData($str);
    //44 
    //45     $final = preg_replace( "#[imgcode](.+?)[/imgcode]#ie", "<img src='{$img_data[0]}' width='{$img_data[1]}' height='{$img_data[2]}' align='{$img_data[3]}' />", $data );
    //46 
    //47     return $final;
    //48 }
    //49 
    //50 function getImgData($data)
    //51 {
    //52     $img_data = explode(':', $data);
    //53 
    //54     return $img_data;
    //55 } 

  11. #11
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, sorry. My grasp of the preg_ functions isnt that strong. Try this one:

    Code:
    function doPicEncode($data)
    {
        $str = preg_replace( "#[imgcode](.+?)[/imgcode]#ie", "getImgData('\\1')", $data );
        $img_data = getImgData($str);
        
        $final = str_replace( $data, "<img src='{$img_data[0]}' width='{$img_data[1]}' height='{$img_data[2]}' align='{$img_data[3}' />", $data );
    
        return $final;
    }
    
    function getImgData($data)
    {
        $img_data = explode(':', $data);
        
        return $img_data;
    }
    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  12. #12
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    New errors

    This Code:
    PHP Code:
    function doPicEncode($data)
    {
        
    $str preg_replace"#[imgcode](.+?)[/imgcode]#ie""getImgData('\\1')"$data );
        
    $img_data getImgData($str);

        
    $final str_replace$data"<img src='{$img_data[0]}' width='{$img_data[1]}' height='{$img_data[2]}' align='{$img_data[3]}' />"$data );

        return 
    $final;
    }

    function 
    getImgData($data)
    {
        
    $img_data explode(':'$data);

        return 
    $img_data;

    used on this input, e.g. $data

    [IMGCODE]"Ithganin-colorweb-small.jpg::200:278:right"[/IMGCODE] I am old now and I fear I have little time left to chronicle all that I have learned in my travels. My life has been both blessed and cursed. I am a Child of the Waking Dream, touched by fate and bound to a being in another far off world. The common folk would call me a hero, the great Pantheon, a threat. I walk a fine line between the light and the shadows. Stalking the nightmares sent from a mystical realm I can neither see nor visit.


    There are others like me and it is for them that I try in these late years to chronicle what I know. I have been on “The Hunt” for more than three decades and I have seen most of what there is to see of this world. In this tome I will introduce you as best I can to all the world, its kingdoms, its people and its ways.


    Take heed, the hunt never ends for the Children of the Waking Dream until we are cold in our graves. That time may be short or long, glorious or tragic, and what you learn here may make the difference.



    Dimitri Amadon


    An excerpt from chronicle of the first child



    “The Hunt: Rise of Evil” is a d20 campaign setting by Mystic Eye Games. In this book you will be immersed into the dark world of Gothos. You will find a new and fantastic land where the dreams and nightmares of our sleeping Earth folk find their way into this mystical world.


    This unique campaign setting will give you new rules, kingdoms, classes, races, magic, and much more. Play in our world or simply apply all that you find here to any d20 game.


    Become a Child of the Waking Dream and join the hunt today!


    This section has replaced our mini-guide to Gothos and will continue to grow in the days to come!
    created this output:

    <img src='[ArrayArrayArraythArrayn-ArrayrwArrayall.jpArrayArrayArrayArrayArray>Array Array nArray Arrayar Array lArray tArray lArray ArraynArray all that Array lArrayArrayn Arrayls. ArrayfArrayArrayth blArrayArray ArrayArray aArrayhArray Array WakArray ArrayaArrayuArrayArray anArrayunArray a bArray ArraythArrayff wArray. ThArrayArrayArraylk wArray ArrayArrayrArray Arrayat PanthArrayat. ArraynArraynArraytwArray lArray thArrayArraynArray nArrayarArraynt frArrayystArrayalArray ArrayArrayr sArrayr vArrayt.
    <br>
    <br>
    <br>ThArray arArraythArraykArrayArray Arrays fArrayArray try ArraysArray yArray ArraynArray what Arrayw. Array bArrayn “ThArrayr Array than thrArrayArrayArray Array sArrayArrayf what thArray Array sArrayf thArrayrlArrayn thArrayArray wArrayntrArrayArrayu as bArray Array all thArrayrlArrayts kArrayArrays, ArrayArray anArrayts ways.
    <br>
    <br>
    <br>TakArrayArray hunt nArrayr Arrays fArray ArraylArrayn Array WakArray ArrayaArrayl wArray Array Arrayur Arrays. That tArray Array shArrayr lArray, ArrayrArrayr traArray, anArrayu lArrayrArrayay Array thArrayArrayrArrayArrayArraytrArrayaArrayxArrayArrayhrArrayArray Array fArrayhArray
    <br></Array Hunt' width=' RArray ArrayvArrays a ArrayaArrayArrayttArray by ArrayArrayyArrayaArrayn thArrayArrayu wArray ArrayArrayArrayntArray ArrayrlArrayf Arrays. YArrayll fArray a nArray fantastArray whArray thArrayrArrays anArrayArrayarArrayf ArrayArraynArrayarth fArraynArrayArrayntArrays ArrayArrayrlArrays unArray ArraypaArrayttArray wArrayArray yArrayw rulArraynArrayArraylassArrayArrayaArray, anArrayuArrayArray. Play Arrayur wArray ArrayArrayu fArray hArray tArray20 ArrayArrayArrayArrayhArray Array WakArray ArrayaArray jArray hunt tArrays sArrayArrayplaArray ArrayArray-ArrayArray Arrays anArrayll ArraynuArray Arrayw Array Array Arraye!' height='' align='' />
    So Something is fishy here

  13. #13
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    eep!

    More research needed I think........
    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  14. #14
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Phil.Roberts
    eep!

    More research needed I think........
    Well I'll mess around with it but please post any advice/solution to this problem you might find

  15. #15
    SitePoint Enthusiast Liquide's Avatar
    Join Date
    Oct 2002
    Location
    Katrineholm, Sweden
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the final example what the string I want to create into an image tag will look like:
    [IMGCODE]"8:200:278:right"[IMGCODE]


    Here is the final function that will convert the arrays that will be between [IMGCODE] and [/IMGCODE] into image tags. (observe that this function works fine, it is passing the string to newpicencode() I have problems with).

    PHP Code:
    function newpicencode($pic_input){

        list(
    $pic_file$pic_width$pic_height$pic_align) = explode(":"$pic_input);

        
    //we connect to our database
        
    $connection=mysql_connect ("localhost""username""password") or die ('I cannot connect to the database.');

        
    //we select our current database
        
    mysql_select_db ('huntroec_files'$connection);

        
    // We do our SQL query to show our data
        
    $query=mysql_query ("SELECT * FROM huntroe_images WHERE ID='$pic_file'");
        
    // we select the data to show!

        
    $content=mysql_fetch_array($query);

        
    // We deconnect from the database
        
    mysql_close($connection);

        
    $pic_Temp "<IMG SRC='Uploads/Images/".$content[Image]."' HEIGHT='".$pic_height."' WIDTH='".$pic_width."' ALIGN='".$pic_align."'>";

        return 
    $pic_Temp;



Bookmarks

Posting Permissions

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