Jump to content

jimbob26

Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jimbob26's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Maybe everyone has gone a little offtrack, all you need is a simple function called "in_array" ie: [code] $message = "Hello ()"; $words=array("@","{","(","$","(","}","+"); for($i=0;$i<strlen($message);$i++) {    if(in_array($message[$i],$words)) {       echo "$message.<br>sorry charecter used not allowed. <b>".$message[$i]." at position $i</b>";    } } [/code] Maybe thhat will help?
  2. Hello, I currently have this XML file for images: [code] <?xml version="1.0"?> <images>     <image src="a.png">         <name>a</name>         <description>Jim a</description>     </image>     <image src="b.png">         <name>b</name>         <description>Jim b</description>     </image> </images> [/code] And also have this php file: [code] <?php $open_stack = array(); $parser = xml_parser_create(); xml_set_element_handler($parser,"start_handler","end_handler"); xml_set_character_data_handler($parser,"character_handler"); xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); xml_parse($parser,implode("",file("images.xml"))) or die(format_error($parser)); xml_parser_free($parser); function start_handler($p,$name,$atts) {     global $open_stack;     $open_stack[] = array($name,""); } function character_handler($p,$txt) {     global $open_stack;     $cur_index = count($open_stack)-1;     $open_stack[$cur_index][1] .= $txt; } function end_handler($p,$name) {     global $open_stack;     $el = array_pop($open_stack);     if($name=="name") {         print "<b>$el[1]</b>";     }     if($name=="description") {         print "<i>$el[1]</i><br>";     } } function format_error($p) {     $code = xml_error_code($p);     $str = xml_error_string($code);     $line = xml_get_current_line_number($p);     return "XML ERROR ($code): $str at line $line"; } ?> [/code] This works fine but im not sure how to extract the src attribute from the image tag (<image src="a.png">). Everything else is working fine, both the name and description of the file is being outputted correctly. Any help is greatly appreciated. Thanks in advance, jim
  3. Hello, i current have this class for a template: [code] class template {    function load($filepath) {       $this->template = file_get_contents($filepath);    }    function replace($var, $content) {       $this->template = str_replace("{$var}", $content, $this->template);    }    function display() {         print $this->template;    } } $template = new template; $template->load("html_file.htm"); $template->replace("{item}", "replaced item!!"); $template->display(); [/code] and the html file contains {item} in it and when the script is run, it replaces the "{item}" with "replaced item!!". However, I now want to repeat the replacment so its like this: [code] $template->replace("{item}", array("Item 1","Item 2","Item 3","Item 4")); [/code] and the html file: [code] {startloop} {item} {endloop} [/code] I need some help so that the {item} is replaced and repeated so that all values in the array appear. so far i have: [code] function replace($var, $content = array()) {       if(preg_match ("#(\{startloop\})(.+?)(\{endloop\})#", $this->template, $middle)) {             foreach($content as $content_array) {                   $this->template = str_replace("{$var}", $content_array, $middle[2]);             }       } } [/code] However this does not work... any help would be much appreciated. Thanks in advance, jimbob.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.