play_ Posted June 3, 2006 Share Posted June 3, 2006 What i plan on doing is, when i post code on my website, i want it to be colored and pretty (like dreamweaver as you type).So i am assuming the best way of doing this, is use gettype() for every word and assign different colors to different types.the only problem is, gettype() is saying everyting is a string, even when i enter a number in the textarea.[code]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><textarea cols="40" rows="9" name="text"></textarea><br /><input type="submit" value="submit" name="submit"></form><?phpif(isset($_POST['submit'])) { $text = $_POST['text']; echo gettype($text);}?>[/code]you can see it in action here: [a href=\"http://ficti0n.com/del.php\" target=\"_blank\"]http://ficti0n.com/del.php[/a]So i thought maybe i should use a bunch of if statements. something the following:if($text == 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 0) { $font = '<font color="red">';}But then i thought, how would do that with classes and objects?Any help is appreciated. Thanks/(btw this is just a sample of the code extracted from the real one. in case it makes a difference, here's everything i have):[code]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><textarea cols="40" rows="9" name="text"></textarea><br /><input type="submit" value="submit" name="submit"></form><?phpfunction evaluate($text) { $exploded = explode(' ', $text); $number_of_words = sizeof($exploded); for ($i = 0; $i < $number_of_words; $i++) { echo $i.') '.$exploded[$i].' <---'.gettype($exploded[$i]).'<br> '; }}if(isset($_POST['submit'])) {$text = $_POST['text'];evaluate($text); }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11068-gettype-giving-me-wrong-type/ Share on other sites More sharing options...
jeremywesselman Posted June 3, 2006 Share Posted June 3, 2006 If you want to check for a number, you can use [a href=\"http://www.php.net/manual/en/function.is-numeric.php\" target=\"_blank\"]is_numeric()[/a].There are also string checks.[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--] Quote Link to comment https://forums.phpfreaks.com/topic/11068-gettype-giving-me-wrong-type/#findComment-41369 Share on other sites More sharing options...
play_ Posted June 3, 2006 Author Share Posted June 3, 2006 [!--quoteo(post=379538:date=Jun 3 2006, 12:33 AM:name=jeremywesselman)--][div class=\'quotetop\']QUOTE(jeremywesselman @ Jun 3 2006, 12:33 AM) [snapback]379538[/snapback][/div][div class=\'quotemain\'][!--quotec--]If you want to check for a number, you can use [a href=\"http://www.php.net/manual/en/function.is-numeric.php\" target=\"_blank\"]is_numeric()[/a].There are also string checks.[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--][/quote]Thank you. php.net has this:is_bool()is_null()is_float()is_int()is_string()is_object()is_array()But, why is gettype() returning a string every time? Quote Link to comment https://forums.phpfreaks.com/topic/11068-gettype-giving-me-wrong-type/#findComment-41392 Share on other sites More sharing options...
jeremywesselman Posted June 3, 2006 Share Posted June 3, 2006 I think it returs a string every time because it is in quotes. I did a few tests and this:[code]<?php$text = 23;?>[/code]returns integer. But if I put it in quotes, it returns a string.[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--] Quote Link to comment https://forums.phpfreaks.com/topic/11068-gettype-giving-me-wrong-type/#findComment-41394 Share on other sites More sharing options...
play_ Posted June 3, 2006 Author Share Posted June 3, 2006 [!--quoteo(post=379563:date=Jun 3 2006, 03:09 AM:name=jeremywesselman)--][div class=\'quotetop\']QUOTE(jeremywesselman @ Jun 3 2006, 03:09 AM) [snapback]379563[/snapback][/div][div class=\'quotemain\'][!--quotec--]I think it returs a string every time because it is in quotes. I did a few tests and this:[code]<?php$text = 23;?>[/code]returns integer. But if I put it in quotes, it returns a string.[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--][/quote]right. that works fine.But in the example i have posted, i didn't put it in quotes. It was taken from the text area. Quote Link to comment https://forums.phpfreaks.com/topic/11068-gettype-giving-me-wrong-type/#findComment-41397 Share on other sites More sharing options...
kenrbnsn Posted June 3, 2006 Share Posted June 3, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]But in the example i have posted, i didn't put it in quotes. It was taken from the text area.[/quote]That is because everything returned from a form is type "text" by definition.If you want to show PHP code in color, you should look at the [a href=\"http://www.php.net/highlight_string\" target=\"_blank\"]highlight_string()[/a] and [a href=\"http://www.php.net/highlight_file\" target=\"_blank\"]highlight_file()[/a] functions.Ken Quote Link to comment https://forums.phpfreaks.com/topic/11068-gettype-giving-me-wrong-type/#findComment-41429 Share on other sites More sharing options...
play_ Posted June 3, 2006 Author Share Posted June 3, 2006 [!--quoteo(post=379598:date=Jun 3 2006, 08:10 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 3 2006, 08:10 AM) [snapback]379598[/snapback][/div][div class=\'quotemain\'][!--quotec--]That is because everything returned from a form is type "text" by definition.If you want to show PHP code in color, you should look at the [a href=\"http://www.php.net/highlight_string\" target=\"_blank\"]highlight_string()[/a] and [a href=\"http://www.php.net/highlight_file\" target=\"_blank\"]highlight_file()[/a] functions.Ken[/quote]Thank you very much.No idea that function existed\However, i'd like to specify my own colors. so ill have to make my own version of it Quote Link to comment https://forums.phpfreaks.com/topic/11068-gettype-giving-me-wrong-type/#findComment-41504 Share on other sites More sharing options...
poirot Posted June 3, 2006 Share Posted June 3, 2006 You can change the color on runtime, using ini_set():[a href=\"http://www.php.net/manual/en/ref.misc.php#ini.syntax-highlighting\" target=\"_blank\"]http://www.php.net/manual/en/ref.misc.php#...ax-highlighting[/a] Quote Link to comment https://forums.phpfreaks.com/topic/11068-gettype-giving-me-wrong-type/#findComment-41514 Share on other sites More sharing options...
play_ Posted June 3, 2006 Author Share Posted June 3, 2006 [!--quoteo(post=379684:date=Jun 3 2006, 02:40 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 3 2006, 02:40 PM) [snapback]379684[/snapback][/div][div class=\'quotemain\'][!--quotec--]You can change the color on runtime, using ini_set():[a href=\"http://www.php.net/manual/en/ref.misc.php#ini.syntax-highlighting\" target=\"_blank\"]http://www.php.net/manual/en/ref.misc.php#...ax-highlighting[/a][/quote]Thank you.Quick question:I see i can use highlight_file, highlight_string and show_source to display souce code. But they all highlight the syntax.Im on a mission here to make a syntax-highlighting function on my own, so i'd like the text not to comeback highlited by defautl. can that happen? Quote Link to comment https://forums.phpfreaks.com/topic/11068-gettype-giving-me-wrong-type/#findComment-41596 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.