Jump to content

mentalist

Members
  • Posts

    291
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by mentalist

  1. lol, PREG_SPLIT_DELIM_CAPTURE

     

    $s="Dorothy lived in the midst of the great Kansas prairies, with Uncle Henry, who was a farmer, and Aunt Em, who was the farmer's wife";
    $k = preg_split("/[\s]+|([,;:]+)/", $s,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
    foreach($k as $e){
    	echo "_".$e."_<br />";
    }
    
  2. I have a sentence of say English litriture, i'm after splitting it into words, but the commas (and such, :, ;) are to be treat as a word them selves, i.e. so I can know where they are. Full stops / periods can be ignore since previously split on them.

     

    $keywords = preg_split("/[\s]+/", $content);
    
  3. It could be more adaptive or even maybe written in a one liner, but here's my quick hack...

     

    <?php
    //	Simple CSS Parser
    //	www.rawstar7.co.uk/site
    
    $fn="tmp/style.css";
    $f = fopen($fn, "rb");
    $contents = fread($f, filesize($fn));
    fclose($f);
    
    $a=css_parse($contents);
    $out=css_print($a);
    
    function css_parse($s){
    	
    	//	STRIP OUT COMMENTS (Can be done elsewhere or missed out completely!)
    	$s = preg_replace('!/\*.*?\*/!s', '', $s);
    	$s = preg_replace('/\n\s*\n/', "\n", $s);
    	
    	//	SPLIT BY "}"
    	$a=explode("}",$s);
    	$acss=array();
    	foreach($a as $e){
    		//	SPLIT BY "{"
    		$aa=explode("{",$e);
    		
    		//	SPLIT NAMES LIST
    		$anames=preg_split("/[\s,]+/", trim($aa[0]));
    		
    		//	SPLIT TAGS LIST
    		$atags=explode(";",$aa[1]);
    		
    		//	SPLIT INDIVIDUAL TAGS INTWO K => V PAIRS
    		
    		//	BUNDLE IT UP 
    		$acss[]=array($anames,$atags);
    	}
    	return $acss;
    }
    
    function css_print($a){
    	$sret= "<table>";
    	foreach($a as $e){
    		$sret.= "<tr><td>";
    		foreach($e[0] as $ee){
    			$sret.= $ee."<br />";
    		}
    		$sret.= "</td><td>";
    		foreach($e[1] as $ee){
    			$sret.= $ee."<br />";
    		}
    		$sret.= "</td></tr>\n";
    	}
    	$sret.= "</table>";
    	
    	return $sret;
    }
    ?>
    
    <html><head>
    <style> table,th,td {	border: 1px solid #000; 	vertical-align: text-top;	} </style>
    </head><body>
    <?php echo $out; ?>
    </body></html>
    
  4. In this example i'm scanning a css file for colour hash codes...

     

    $match='/(#[a-f0-9]{3,6})/is';	//	matches colour hashes from 3 to 6 in length
    preg_match_all($match, $s, $a, PREG_PATTERN_ORDER);
    That works ok for now, what i'm after is how once matched as above how to get some text from before the mmatch returned as a seperate group.

     

    Example css:

    body {

    background: #fff;

    }

     

    a {

    color: #000;

    text-decoration: none;

    }

    At the moment i'm just returned "#fff" and "#000", what i'm after is ("#fff","body") and ("#000","a"). So basically after match come back to before "{" and either to start of file or next "}".

     

    Any help please?

  5. @mentalis: I don't think that is what the instructions are asking for. you're describing the solution for data to flow across a row then create a new row after n records. What I am reading is that each row is a complete record with each column representing a different piece of data for that record.

    ...

    Oops, assumed! Zatox, try that next ;)

  6. Just for info's sake...

     

    There may be a way using the HTML5 canvas, create it at a size then use canvas.scale(), there is a way to save this image ut can't remember it since never used it, only drawback is that it may have to be done clientside if that's acceptable?

  7. You could do it in page by page like various registrations (say on dating sites), so they indicate the info for the new field, then the form is generated as required on the next page.

     

    To do it in one page you would need to use Javascript and maybe Ajax.

     

    Is that what you're after?

×
×
  • 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.