stringClass.php
[code]<?php
		/*----------------------------------------------
		-------------------------------------------------
		DONT REMOVE THIS BLOCK!!!
		--------------------------------------------------------
		Copyright
		Created by: libia
		Created on: 15-09-07 (DD-MM-YY)
		--------------------------------------------------------
		You can use this script,
		but you may NOT call it YOUR script!
		--------------------------------------------------------
		-----------------------------------------------------*/

//the class
class String
{
	//some variables
	public $error;
	public $errno;
	protected $string;
	protected $finalString;
	protected $aantArgs;
	protected $bindArgs;
	protected $prepared;
	protected $bonden;
	protected $paramAant;
	
	//setting values for the variables
	function __construct()
	{
		$this->error = "No error's yet";
		$this->errno = 0;
		$this->string = '';
		$this->finalString = '';
		$this->aantArgs = 0;
		$this->bindArgs = '';
		$this->prepared = false;
		$this->bonden = false;
		$this->paramAant = 0;
	}
	
	//setting the first sentance
	function prepare($prepareString)
	{
		if($this->errno == 0)
		{
			if(!$this->prepared)
			{
				if(!empty($prepareString))
				{
					$this->string = htmlspecialchars($prepareString, ENT_QUOTES);
					$this->prepared = true;
				}
				else
				{
					$this->error = "String is empty!";
					$this->errno = 1001;
				}
			}
			else
			{
				$this->error = "String is already prepared!";
				$this->errno = 1000;
			}
		}
	}
	
	//add the user values
	function bind_param()
	{
		if($this->errno == 0)
		{
			if($this->prepared)
			{
				$this->bindArgs = func_get_args();
				$this->aantArgs = count($this->bindArgs);
				if($this->param_count() == $this->aantArgs)
				{
					$this->finalString = $this->string;
					for($i = 0; $i < $this->aantArgs; $i++)
					{
						$this->finalString = preg_replace("/\?/", htmlspecialchars($this->bindArgs[$i], ENT_QUOTES), $this->finalString, 1);
					}
					$this->bonden = true;
				}
				elseif($this->param_count() > $this->string)
				{
					$this->error = "Not enough arguments given in the bind_param() function (" . $this->aantArgs . " of " . $this->param_count() . ")";
					$this->errno = 1004;
				}
				else
				{
					$this->error = "To much arguments given in the bind_param() function (" . $this->aantArgs . " of " . $this->param_count() . ")";
					$this->errno = 1005;
				}
			}
			else
			{
				$this->error = "String not prepared yet!";
				$this->errno = 1002;
			}
		}
	}
	
	//return the string
	function execute()
	{
		if($this->errno == 0)
		{
			if($this->prepared && $this->bonden)
			{
				return $this->finalString;
			}
			elseif(!$this->prepared)
			{
				$this->error = "String not prepared yet!";
				$this->errno = 1002;
			}
			else
			{
				$this->error = "Params are not bonden yet!";
				$this->errno = 1003;
			}
		}
	}

	//gives the amount of question marks (?) is the sentence
	function param_count()
	{
		if($this->errno == 0)
		{
			$this->paramAant = 0;
			if($this->prepared)
			{
				for($i = 0; $i < strlen($this->string); $i++)
				{
					if($this->string[$i] == '?')
					{
						$this->paramAant += 1;
					}
				}
				return $this->paramAant;
			}
			else
			{
				$this->error = "String not prepared yet!";
				$this->errno = 1002;
			}
		}
	}
	
	//clears the results
	function free_result()
	{
			$this->finalString = '';
			$this->aantArgs = 0;
			$this->bindArgs = '';
			$this->string = '';
	}
	
	//sets everything to it's standard value
	function close()
	{
		$this->__construct();
	}
}
?>[/code]

voorbeeld.php
[code]<?php
		/*----------------------------------------------
		-------------------------------------------------
		DONT REMOVE THIS BLOCK!!!
		-------------------------------------------------
		Copyright
		Created by: libia
		Created on: 15-09-07 (DD-MM-YY)
		-------------------------------------------------
		You can use this script,
		but you may not call it your script!
		-------------------------------------------------
		----------------------------------------------*/
error_reporting(E_ALL);

//include the class!
include("stringClass.php");

//and a little example
$string = new String();
$string->prepare("The ? was ? over the ?");
if($string->errno == 0)
{
	echo 'There were ' . $string->param_count() . ' params setten<br />';
	if($string->errno == 0)
	{
		$string->bind_param("dog", "jumping", "airplane");
		if($string->errno == 0)
		{
			echo $string->execute() . '<br />';
			if($string->errno == 0)
			{
				$string->bind_param("Wolf", "rolling", "lava");
				if($string->errno == 0)
				{
					echo $string->execute();
				}
				else
					echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
			}
			else
				echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
		}
		else
			echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
	}
	else
		echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
	echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';

$string2 = new String();
$string2->prepare("Lol loL ?");
if(trim($string2->errno) == 0)
{
	$string2->bind_param($string->execute());
	if($string2->errno == 0)
	{
		echo '<br /><br />' . $string2->execute() . '<br />';
	}
	else
		echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
}
else
	echo '<b>(error: line ' . __line__ . ') ' . $string->errno . ': ' . $string->error . '</b>';
$string2->close();

//you may use close or free_result + close, it's just what you prefer!
$string->free_result();
$string->close();
?>[/code]