Skip to content

Instantly share code, notes, and snippets.

@hungneox
Last active August 29, 2015 13:58
Show Gist options
  • Save hungneox/9997750 to your computer and use it in GitHub Desktop.
Save hungneox/9997750 to your computer and use it in GitHub Desktop.
Python string function vs PHP string function
<?php
$parrot = "Norwegian Blue";
echo strlen($parrot);
echo strtolower($parrot);
echo strtoupper($parrot);
$pi = 3.14
echo $pi;
if(is_string($pi)):
echo "string";
else:
echo "not a string";
endif;
parrot = "Norwegian Blue"
print len(parrot)
print parrot.lower()
print parrot.upper()
pi = 3.14
print str(pi) #in Python you need to convert number to string in order to print it out
original = raw_input("Enter a word:")
## the function isalpha() which returns False since the string contains non-letter characters.
if len(original) > 0 and original.isalpha():
print original
else:
print "empty"
print "Please input somethings:"
user_input = gets.chomp
temp = user_input.to_i
if temp.is_a?(String)
print "string"
else
print "is not a string"
end
if user_input.empty?
print "Please enter a non empty string:"
user_input = gets.chomp
end
user_input.downcase!
if user_input.include? "s"
user_input.gsub!(/s/,"th")
puts "#{user_input}"
else
print user_input
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment