Home 2017-05-30T16:12:47+00:00

Convert PHP code into Ruby!

Find out how to change PHP code into Ruby code using PHP to Ruby as your converter. We are on a quest to provide a conversion resource for PHP developers looking to migrate their code to Ruby. Every standard PHP function will be ported to show how it can be done in Ruby. If you find a PHP function which has not been converted yet, feel free to help us out by submitting conversion code yourself.

1811, 2010

file_get_contents

By | November 18th, 2010|Categories: PHP, Ruby|Tags: , , |1 Comment

The file_get_contents() function in PHP reads the content of a file into a string (or reads the HTML of a web page into a string).

PHP

$body = file_get_contents( 'http://www.google.com' );
echo $body;

/* 
... HTML source of www.google.com ...
*/

To replicate this functionality in Ruby, we will use the Net/HTTP class from Ruby.

1111, 2010

array_fill_keys

By | November 11th, 2010|Categories: PHP, Ruby|Tags: , , , |1 Comment

The array_fill_keys() function in PHP allows you to populate the values of an array while specifying its keys.

PHP

$keys = array('write', 'debug', 'execute');
$result = array_fill_keys($keys, 'code');
var_export($result);
// => array('write' => 'code', 'debug' => 'code', 'execute' => 'code')

To replicate this functionality in Ruby, we need to use a Hash object, since […]

1910, 2010

array_merge

By | October 19th, 2010|Categories: PHP, Ruby|Tags: , , , , |1 Comment

The array_merge() function in PHP merges 2 arrays by appending the second array onto the first array, and returning the resulting array.

The way to do this in Ruby depends on the type of data – if dealing with associative arrays (known as a hash in Ruby), we can use the […]

1310, 2010

array_fill

By | October 13th, 2010|Categories: PHP, Ruby|Tags: , , , , , |1 Comment

The array_fill() function in PHP allows an array to be populated (i.e. filled) with a particular value.

PHP

$a = array_fill(3, 5, 'php');
print_r($a);
/*
Array (
	[3] => php
	[4] => php
	[5] => php
	[6] => php
	[7] => php
)
*/

In Ruby this is not really possible because Ruby arrays must have their keys filled in the […]

1904, 2010

array_flip

By | April 19th, 2010|Categories: PHP, Ruby|Tags: , , , |3 Comments

The array_flip() PHP function changes all the keys in an array into values, and all the values into keys.

PHP

$a = array('apple' => 1, 'ibm' => 2, 'sun' => 3);
$flipped = array_flip($a);
print_r($flipped);
/*
Array (
	[1] => apple
	[2] => ibm
	[3] => sun
)
*/

To replicate this functionality in Ruby, we will use a Hash […]

Autonomous Standing Desk

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.