www.webdeveloper.com
Results 1 to 6 of 6

Thread: Can someone help with this please?

  1. #1
    Join Date
    Oct 2013
    Posts
    9

    Can someone help with this please?

    Hi,

    I have an issue.

    I am generating a php file with some contents in it such as an array.
    The array values are coming from database values.
    The array is as follows:

    PHP Code:
    $array = array('key' => 'key_name''value' => 'db_value'); 
    However, the db_value needs to be able to not break the php code such as special characters like !"$%^&*();'@:][{}#~?><,./

    Because the array 'Value' contents is wrapped in '' (single quotes) I am thinking that there could be a possibility of it breaking the php code and making the array not work.

    Whats your thoughts on this?

    Thanks for your help.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,538
    If the value is coming from a variable or array element, no quoting is necessary: that's only needed for string literals.
    PHP Code:
    $array = array('key' => 'key_name''value' => $valueRetrievedFromDatabase); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2013
    Posts
    9
    I don't think you understood what I meant or I didn't explain it correctly. Basically this array is being saved to a php page after clicking a button. So yes the value is coming from the db but it the PHP thats being generated is going to be saved as a php file for use else where.

    Do you see what I mean mate?

    Thanks

  4. #4
    Join Date
    Oct 2013
    Posts
    9
    This is what is actually happening:


    PHP Code:

    <?php //DB LOOP START ?>
    $array = array('key' => '<?php echo $row['key']; ?>', 'value' => '<?php echo $row['value']; ?>');

    <?php //DB END LOOP ?>
    Then after that the file gets saved and called install.php

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,538
    Sounds like a job for htmlspecialchars() or htmlentities()?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Oct 2013
    Posts
    9
    thanks mate that sorted it.

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