Instantly convert code snippets from PHP to Elixir with our free online code converter. Transform your code easily and accurately.
Experience the full potential of AI-driven code conversion and transformation!
We prioritize your code's security and privacy. Your code is not stored on our servers and is only temporarily processed for conversion. We use OpenAI's secure servers for the conversion process, ensuring your code remains confidential.
PHP is a general-purpose scripting language especially suited to web development.
Elixir is a functional, concurrent, general-purpose programming language.
<?php
function isPalindrome($str) {
$clean = preg_replace("/[^a-zA-Z0-9]/", "", strtolower($str));
return $clean === strrev($clean);
}
// Example usage
echo isPalindrome("A man, a plan, a canal: Panama") ? "true" : "false"; // true
echo "\n";
echo isPalindrome("race a car") ? "true" : "false"; // false
?>
defmodule Palindrome do
def is_palindrome(str) do
clean = str
|> String.downcase()
|> String.replace(~r/[^a-z0-9]/, "")
clean == String.reverse(clean)
end
end
# Example usage
IO.puts Palindrome.is_palindrome("A man, a plan, a canal: Panama") # true
IO.puts Palindrome.is_palindrome("race a car") # false
<?php
function bubbleSort($arr) {
$n = count($arr);
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n - $i - 1; $j++) {
if ($arr[$j] > $arr[$j + 1]) {
$temp = $arr[$j];
$arr[$j] = $arr[$j + 1];
$arr[$j + 1] = $temp;
}
}
}
return $arr;
}
$arr = array(64, 34, 25, 12, 22, 11, 90);
print_r(bubbleSort($arr));
?>
defmodule Sort do
def bubble_sort(list) when length(list) <= 1, do: list
def bubble_sort(list) do
{new_list, swapped} = bubble_step(list, [], false)
if swapped, do: bubble_sort(new_list), else: new_list
end
defp bubble_step([a, b | tail], acc, swapped) when a > b do
bubble_step([a | tail], [b | acc], true)
end
defp bubble_step([a, b | tail], acc, swapped) do
bubble_step([b | tail], [a | acc], swapped)
end
defp bubble_step([a], acc, swapped), do: {Enum.reverse([a | acc]), swapped}
defp bubble_step([], acc, swapped), do: {Enum.reverse(acc), swapped}
end
arr = [64, 34, 25, 12, 22, 11, 90]
IO.inspect Sort.bubble_sort(arr)
Convert PHP to Python
Open ConverterConvert PHP to JavaScript
Open ConverterConvert PHP to TypeScript
Open ConverterConvert PHP to Java
Open ConverterConvert PHP to C
Open ConverterConvert PHP to C++
Open ConverterConvert PHP to C#
Open ConverterConvert PHP to Go
Open ConverterConvert PHP to Dart
Open ConverterConvert PHP to Ruby
Open ConverterConvert PHP to Swift
Open ConverterConvert PHP to Kotlin
Open ConverterConvert PHP to Rust
Open ConverterConvert PHP to Scala
Open ConverterConvert PHP to R
Open ConverterConvert PHP to Haskell
Open ConverterConvert PHP to Julia
Open ConverterConvert PHP to MATLAB
Open ConverterConvert PHP to Lua
Open ConverterConvert PHP to Assembly
Open ConverterConvert PHP to Perl
Open ConverterConvert PHP to Groovy
Open ConverterConvert PHP to F#
Open ConverterConvert PHP to Clojure
Open ConverterConvert PHP to Delphi
Open Converter