Short Tag – Web Development Blog

Entries for the ‘Uncategorized’ Category

PHP str_replace

PHP’s str_replace function will replace every occurrence of the selected string with another string.

echo str_replace("car", "bike", "That car is red!");

The code above displays the text: That bike is red!
Function parameters:
str_replace(searched_string, replacement_string, target_string, count)
searched_string – the string that will be replaced
replacement_string – the string that will be used to replace the searched string
target_string – the string [...]

Stream Context in PHP (The CURL alternative)

In PHP there are several ways to get the content of a URL.
A well known method is using the function file_get_contents().
Another way would be using the cURL classes. The thing is, cURL may not be available an all hosts and you might be forced to use file_get_contents, or you just want to use file_get_contents() because [...]