Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CodeIgniter - Tokenizer Helper
<?php
Class Tokenizer {
public $dataIn = "";
public $response_header = "";
function __construct($linkIn = '', $link = true) {
if ($link) {
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$this->dataIn = @file_get_contents($linkIn, false, stream_context_create($arrContextOptions));
if (isset($http_response_header)) {
$this->response_header = $http_response_header;
} else {
$this->response_header = '?';
}
} else {
$this->dataIn = $linkIn;
}
}
public function eraseTo($target) {
$token_pos = strpos($this->dataIn,$target);
$token_found = false;
if ($token_pos === false) {
$token_found = false;
$this->dataIn = substr_replace($this->dataIn, "", 0, strlen($this->dataIn));
} else {
$token_found = true;
$this->dataIn = substr_replace($this->dataIn, "", 0, $token_pos+strlen($target));
}
return $token_found;
}
public function getTo($target) {
$token_pos = strpos($this->dataIn,$target);
if ($token_pos === false) {
return substr($this->dataIn, 0, strlen($this->dataIn));
} else {
return substr($this->dataIn, 0, $token_pos);
}
}
public function getToEnd() {
return substr($this->dataIn, 0, strlen($this->dataIn));
}
public function find($target) {
$token_pos = strpos($this->dataIn,$target);
return $token_pos;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment