I have an attendance system where users could go in and out the campus, I finished it with this condition:
if($i == 0){
$in = '✔';
$out = '';
}
if($i > 0){
if (strtotime(substr($arr[$i][0],0,10)) == strtotime(substr($arr[$i-1][0],0,10))) {
$count++;
if($count % 2 == 0){
$in = '✔';
$out = '';
}
else{
$in = '';
$out = '✔';
}
}
else{
$count = 0;
$in = '✔';
$out = '';
}
}
However, I was instructed to add a break-in and break-out.
I'm using a hardware wherein it has a database on MS SQL. The types set are:
Type = 1 is In, Type = 2 is Out, Type = 4 is Break Out, and Type = 8 is Break In.
I'm trying to get it using this:
$query = 'SELECT ActualTime, Type FROM TA3.dbo.TimeLogs WHERE TimeLogs.EmployeeID='.$passed.' ORDER BY TimeLogs.ActualTime
$stmt = $conn->query($query);
$stmt->execute();
$arr = $stmt->fetchAll();
if (isset($_POST['Type'])
{
$Type = $_POST['Type'];
}
if($Type == 1)
{
$in = '✔';
$bin = '';
$bout = '';
$out = '';
}
if($Type == 2)
{
$in = '';
$bin = '';
$bout = '';
$out = '✔';
}
if($Type == 4)
{
$in = '';
$bin = '';
$bout = '✔';
$out = '';
}
if($Type == 8)
{
$in = '';
$bin = '✔';
$bout = '';
$out = '';
}
else
{
$in = '✔';
$bin = '';
$bout = '';
$out = '';
}
However, I'm not getting any checks on my table.
Related
i'm writing a php web script with mvc, but i'm concerned about code is safe.
i fear most "eval($str)", but i try a lot of php function string but nothing happened.
$a = func_get_args();
if((func_num_args()-1)%2 == 0){
$str = "";
array_shift($a);
for($i = 0;$i<sizeof($a);$i++){
if($i%2==0){
if(!is_numeric($a[$i])){
if($a[$i] == 'filter'){
$filter=1;
}
$str.= "$".stripslashes($a[$i])." = ";
}else{
$str.= 'page';
}
}else{
if($filter != 1){
if(is_numeric($a[$i])){
$str.= stripslashes($a[$i]).";";
}else{
$str.=1;
}
}else{
$arr = explode("-",$a[$i]);
$dizz = 'array(';
for($j=0;$j<sizeof($arr);$j++){
if(($j%2)==0){
$dizz .= '\''.stripslashes($arr[$j]).'\'=>';
}else{
$dizz .= '\''.stripslashes($arr[$j]).'\',';
}
}
$dizz = rtrim($dizz,',');
$dizz .= ');';
$str.= $dizz;
}
}
}
eval($str);
}
$filter = isset($filter) ? $filter : false;
$page= isset($page) ? $page: '';
$count= isset($count) ? $count: '';
if($count == ''){
switch ($process) {
case 'table':
$count = 40;
break;
case 'detailed':
$count = 3;
break;
case 'mobile':
$count = 12;
break;
default:
$count = '';
break;
}
}
if($count != ''){
if(is_numeric($count )){
if($count <=200 && $count >0){
$count = $count ;
}else{
$count = 40;
}
}else{
$count = 1;
}
}
if(!is_numeric($page)){
$page= 1;
}
to sql query->
$new_filter = "Where ";
if($filter){
foreach ($filteras $key => $value) {
$new_filter .= 'k.'.$key.'='.$value.' and ';
}
$new_filter = rtrim($new_filter,' and ');
$filter= $new_filter;
}else{
$filter= '';
}
$limit = ($limit) ? 'LIMIT 30' : '';
if($id == ''){
$where = $filter;
}else{
$where = $id;
}
$query = 'select * from kullanici as k join kisiler as ki on k.id = ki.kullanici_id join iletisim as i on k.id = i.kullanici_id '.$where.' '.$siralama.' '.$limit;
$query = $this->_db->prepare($query);
$query->execute();
example url:
profile/show/mobile/page/4/count/5/filter/echo-"'xzcxza'"-sadas-asdxc
this results:
$page = 4;$count= 5;$filter= array('echo'=>'%22%27xzcxza%27%22','sadas'=>'asdxc');
I have some data in url
sub_cat.php?s=1&os=3,1&brand=10,9&camera=19&storage=15,13&data=17
I have:
operating systems with id 3 and 1
brands with id 10 and 9
camera with id 19
storage with id 15 and 13
data with id 17
i want to show mobiles having these specifications from sql database
if (isset($_GET['brand'])) {
$sf_brand = $_GET['brand'];
$brand_split = explode(',', $sf_brand);
$sf_brand_len = count($brand_split);
for ($ab=0; $ab < $sf_brand_len; $ab++) {
$append_sf_brand .= 'OR product.product_brand LIKE \''.$brand_split[$ab].'\' ';
}
$append_sf_brand_f = '('.substr($append_sf_brand, 3).')';
}else{
$append_sf_brand_f = '';
}
if (isset($_GET['os'])) {
$sf_os = $_GET['os'];
$os_split = explode(',', $sf_os);
$sf_os_len = count($os_split);
for ($ao=0; $ao < $sf_os_len; $ao++) {
$append_sf_os .= 'OR productspec.prospec_expspec_id LIKE \''.$os_split[$ao].'\' ';
}
$append_sf_os_f = '('.substr($append_sf_os, 3).')';
}else{
$append_sf_os_f = '';
}
if (isset($_GET['camera'])) {
$sf_camera = $_GET['camera'];
$camera_split = explode(',', $sf_camera);
$sf_camera_len = count($camera_split);
for ($ac=0; $ac < $sf_camera_len; $ac++) {
$append_sf_camera .= 'OR productspec.prospec_expspec_id LIKE \''.$camera_split[$ac].'\' ';
}
$append_sf_camera_f = '('.substr($append_sf_camera, 3).')';
}else{
$append_sf_camera_f = '';
}
if (isset($_GET['data'])) {
$sf_data = $_GET['data'];
$data_split = explode(',', $sf_data);
$sf_data_len = count($data_split);
for ($ad=0; $ad < $sf_data_len; $ad++) {
$append_sf_data .= 'OR productspec.prospec_expspec_id LIKE \''.$data_split[$ad].'\' ';
}
$append_sf_data_f = '('.substr($append_sf_data, 3).')';
}else{
$append_sf_data_f = '';
}
if (isset($_GET['storage'])) {
$sf_storage = $_GET['storage'];
$storage_split = explode(',', $sf_storage);
$sf_storage_len = count($storage_split);
for ($as=0; $as < $sf_storage_len; $as++) {
$append_sf_storage .= 'OR productspec.prospec_expspec_id LIKE \''.$storage_split[$as].'\' ';
}
$append_sf_storage_f = '('.substr($append_sf_storage, 3).')';
}else{
$append_sf_storage_f = '';
}
$sf_condition = '(product.product_id LIKE productspec.prospec_product_id) AND '.$append_sf_brand_f.' AND '.$append_sf_os_f.' AND '.$append_sf_camera_f.' AND '.$append_sf_data_f.' AND '.$append_sf_storage_f;
I have query:
$get_brand_query = mysqli_query($connect, "SELECT * FROM product, productspec WHERE $sf_condition");
But it is not working well, so how I can show mobiles can anyone help me thanks.
I have problem that my sms messages are imported with csv, then it is checked if number is ok and how long sms is. My problem is that if text messages is longer then 160 it still enters 1 in databse. But it should start counting, if it is less or equal than 160, it is 1 messages, if it is more than 160 but less or equal than 320 it is two messages and if it is more then it is 3 messages.
Page code is here:
<?php
$link = #mysql_connect("localhost", "admin", "") or die("Error: Database offline.");
mysql_select_db("database", $link);
mysql_query("SET NAMES 'utf8' ", $link);
function detect_type($smstext) {
$type = 0;
$dec_codes = array();
for ($i = 0; $i < strlen($smstext); $i++) {
$symbol = substr($smstext,$i,1);
if (!in_array(ord($symbol), $dec_codes)) { $type = 1; }
}
return $type;
}
$result_array = array();
$unic_numbers = array();
$fp = file_get_contents($_FILES['filename']['tmp_name']);
$fp = str_replace("\r\n", "\n", $fp);
$fp = str_replace("\r", "\n", $fp);
$fp = str_replace("\t", "", $fp);
$rows = explode("\n", $fp);
$imported_rows = 0;
$duplicate_rows = 0;
$error_rows = 0;
$long_rows = 0;
for ($i = 0; $i < sizeof($rows); $i++) {
$data = explode(";", $rows[$i]);
$data[1] = sms_formatNumbers($data[1]); // formating number
$userid = 78;
if(strlen($data[1]) > 9){
if($unic_numbers[$data[1]] != true ){ // unic number check
$unic_numbers[$data[1]] = true;
$imported_rows++;
$fullSMS = iconv("ISO-8859-1","UTF-8", trim($data[2])." ".trim($data[3])." ".trim($data[4]));
if(strlen($fullSMS) > 164){
$long_rows++;
}
if($_POST['action'] == 'send'){
// SMS TEXT
$smstext = str_replace("õ", "ò", $fullSMS);
$smstext = str_replace("Õ", "ò", $smstext);
$type = detect_type($smstext);
// servicegroup
$char2 = substr($data[1], 0, 2);
$char3 = substr($data[1], 0, 3);
$c1 = mysql_query("SELECT * FROM zone_info WHERE country_code = '".$char2."'", $link);
$c2 = mysql_query("SELECT * FROM zone_info WHERE country_code = '".$char3."'", $link);
if (mysql_num_rows($c1) == 1) {
$r = mysql_fetch_array($c1);
$price = $r['price'];
$z = mysql_query("SELECT * FROM zone WHERE id = ".$r['up']."", $link);
$zone = mysql_fetch_array($z);
$zone_id = $zone['id'];
$servicegroup = $zone['servicegroup'];
} else if (mysql_num_rows($c2) == 1) {
$r = mysql_fetch_array($c2);
$price = $r['price'];
$z = mysql_query("SELECT * FROM zone WHERE id = ".$r['up']."", $link);
$zone = mysql_fetch_array($z);
$zone_id = $zone['id'];
$servicegroup = $zone['servicegroup'];
}
require_once("../scripts/number.class.php");
$receiver = "00".$data[1];
$obj = new NumberClass($receiver);
$operator = $obj -> operator_code;
$country = $obj -> code;
$operator_name = $obj -> operator_name;
if(strlen($operator) > 0) {
$er = mysql_query("SELECT * FROM zone_exception WHERE country = ".$country." AND operator = ".$operator."", $link);
if (mysql_num_rows($er) == 1) {
$erand = mysql_fetch_array($er);
$price = $erand['price'];
$servicegroup = $erand['servicegroup'];
}
} else $operator_name = "-";
if ($operator_name == "-") { $servicegroup = $servicegroup; }
else {
if ($operator_name == " First Operator") $servicegroup = "90";
else if ($operator_name == "Second Operator") $servicegroup = "91";
else if ($operator_name == "Third Operator") $servicegroup = "92";
else $servicegroup = $servicegroup;
}
require_once("../core/init.mini.inc.php");
$servicegroup = UserBasedRerouting($receiver, $userid, $operator_name, $servicegroup);
$client_type ='corporative';
$sender = $data[0];
$zone_id = 11;
$client_sms_id = '0';
$client_want_report = '0';
$client_report_url = '';
$amount = 1;
$dt_delaysend = '1970-01-01 00:00:00';
$SMSsent = 0;
$SMStotal = 1;
$smstext_old = $smstext;
while($SMSsent < $SMStotal){
$sql = mysql_query("insert into sms_queue (user_id,client_type,dt_entered,sender,receiver,operator,smstext,sms_type,zone_id,client_sms_id,client_want_report,client_report_url,sms_price,amount,servicegroup,dt_delaysend) values ('$userid','$client_type','".date('Y-m-d H:i:s')."','$sender','$receiver','$operator_name','$smstext',0,'$zone_id','$client_sms_id','$client_want_report','$client_report_url','$price','$amount','$servicegroup','$dt_delaysend')", $link);
$SMSsent++;
}
}
}else{
$duplicate_rows ++;
}
}else{
$error_rows++;
}
}
$result_array['success'] = true;
$result_array['long_sms'] = $long_rows;
$result_array['send_sms'] = $imported_rows;
$result_array['error_sms'] = $error_rows;
$result_array['duplicate_sms'] = $duplicate_rows;
$result_array['action'] = $_POST['action'];
echo json_encode($result_array);
function sms_formatNumbers($number){
$number = (int)$number;
$start_code = (int)substr($number,0,4);
if($start_code < 3780 or $start_code == 3785 or $start_code > 3789){
return $number;
}else{
return '';
}
}
?>
Can someone help me out with that?
Thank you
Try
if(strlen($fullSMS) > 164){
$long_rows = ceil(strlen($fullSMS)/160);
}
instead of
if(strlen($fullSMS) > 164){
$long_rows++;
}
I am using the following code to enter submitted names into the database. The code, when working correctly, should capture the names and other information submitted in the form and create three unique entries in the database. This is not happening. Instead the code is capturing the last name in the three pack and entering its information into the database. You can view the form here beta website. The payment processing script is disabled on the form. What do I need to change in the for loop code to fix this issue? Any assistance is greatly appreciated. Thank you. I have added all of the code that is used in the script below. Hopefully this will give you a better understanding of what is going on in the script.
class DreamModelDream extends JModel {
function getDetails()
{
$session = JFactory::getSession();
if($session->get('dreamticket'))
{
return $session->get('dreamticket');
}
$data = new stdClass();
$data->tickets = -1;
$data->fiftytickets = '';
$data->qty = 0;
$data->fiftyqty = 0;
$data->firstname = '';
$data->firstname2 = '';
$data->firstname3 = '';
$data->lastname = '';
$data->lastname2 = '';
$data->lastname3 = '';
$data->address = '';
$data->address2 = '';
$data->address3 = '';
$data->city = '';
$data->city2 = '';
$data->city3 = '';
$data->postal = '';
$data->postal2 = '';
$data->postal3 = '';
$data->phone = '';
$data->phone2 = '';
$data->phone3 = '';
$data->altphone = '';
$data->altphone2 = '';
$data->altphone3 = '';
$data->email = '';
$data->email2 = '';
$data->email3 = '';
$data->giftname = '';
$data->giftaddress = '';
$data->giftcity = '';
$data->giftpostal = '';
$data->sec_firstname = '';
$data->sec_firstname2 = '';
$data->sec_firstname3 = '';
$data->sec_lastname = '';
$data->sec_lastname2 = '';
$data->sec_lastname3 = '';
$data->agegroup = 0;
$data->expm = 0;
$data->expy = 0;
$data->nameoncard = '';
$data->cctype = '';
$data->ccnum = '';
$data->Media_Radio = false;
$data->Media_TV = false;
$data->Media_Newspaper = false;
$data->Media_Mail = false;
$data->Media_Web = false;
$data->Media_Kinsmen_Member = false;
$data->Media_Other = false;
$data->Radio_CJCY = false;
$data->Radio_MY96 = false;
$data->Radio_ROCK = false;
$data->Radio_CHAT = false;
$data->Radio_POWER = false;
$data->Radio_Other = false;
$data->total = false;
$data->billingphone = '';
$data->agree = 0;
$data->ord_type = 0;
$data->creditcard = '';
$data->user_ip = $_SERVER['REMOTE_ADDR'];
return $data;
}
function getConfirmDetails()
{
$post = JRequest::get('post');
$ticket = new stdClass();
foreach($post as $key => $value)
{
$ticket->$key = $value;
}
$session = JFactory::getSession();
$session->set('dreamticket', $ticket);
if(!strlen($post['firstname'])){
return "Your first name is missing<br>";
}
if(!strlen($post['lastname'])){
return "Your last name is missing<br>";
}
if(!strlen($post['address'])){
return "Your address is missing<br>";
}
if(!strlen($post['city'])){
return "Your city is missing<br>";
}
if(!strlen($post['postal'])){
return "Your postal code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal'])) {
//return "Your postal code is invalid for this province<br>";
}
if(!strlen($post['phone'])){
return "Your phone number is missing<br>";
}
if(!strlen($post['email'])){
return "Your email is missing<br>";
}
if($post['tickets'] == '-1'){
////////// TICKET 2
if(!strlen($post['firstname2'])){
return "Your first2 name is missing<br>";
}
if(!strlen($post['lastname2'])){
return "Your last2 name is missing<br>";
}
if(!strlen($post['address2'])){
return "Your address2 is missing<br>";
}
if(!strlen($post['city2'])){
return "Your city2 is missing<br>";
}
if(!strlen($post['postal2'])){
return "Your postal2 code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal2'])) {
//return "Your postal2 code is invalid for this province<br>";
}
if(!strlen($post['phone2'])){
return "Your phone number2 is missing<br>";
}
/////////////Ticket 3
if(!strlen($post['firstname3'])){
return "Your first name3 is missing<br>";
}
if(!strlen($post['lastname3'])){
return "Your last name3 is missing<br>";
}
if(!strlen($post['address3'])){
return "Your address3 is missing<br>";
}
if(!strlen($post['city3'])){
return "Your city3 is missing<br>";
}
if(!strlen($post['postal3'])){
return "Your postal code3 is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal3'])) {
//return "Your postal code3 is invalid for this province<br>";
}
if(!strlen($post['phone3'])){
return "Your phone number3 is missing<br>";
}
}
//////// END TICKET CHECK
if(!strlen($post['nameoncard'])){
return "Your Name on Credit Card is missing<br>";
}
if($post['cctype'] == "Please select one"){
return "Your Credit Card Type is missing<br>";
}
if(!strlen($post['ccnum'])){
return "Your Credit Card Number is missing<br>";
}
if(!strlen($post['billingphone'])){
return "Your billing phone number is missing<br>";
}
if(!strlen($post['agree'])){
return "Your must agree to the Lottery rules in order to proceed<br>";
}
return $ticket;
}
function process()
{
$user = JFactory::getUser();
jimport('joomla.database.table');
$params = JComponentHelper::getParams('com_dream');
$session = JFactory::getSession();
$data = $session->get('dreamticket');
if(!is_object($data))
{
return false;
}
$dif = strtotime("-1 hour");
$timestamp = date("F j, Y, g:i a",$dif);
$ord_id = date('ymdHis') . rand(1000,9999);
$ticket_total = (int) (($data->tickets == '-1') ? '250' : (int) $data->tickets * 100);
$fiftyticket_total = (int) (($data->fiftytickets == '0') ? '' : (int) $data->fiftytickets * 10);
$ordertotal = $ticket_total + $fiftyticket_total;
if(strlen($data->expm) == 1)
{
$data->expm = '0'.$data->expm;
}
if(strlen($data->expy) != 2)
{
$data->expy = substr($data->expy, 2, 2);
}
$data->total = $ordertotal;
JTable::addIncludePath(JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_dream'.DS.'tables');
$table = JTable::getInstance('Tickets', 'Table');
$table->auth = $auth;
$table->billingphone = $data->billingphone;
$table->Media_Radio = isset($data->Media_Radio) ? 1 : 0;
$table->Media_TV = isset($data->Media_TV) ? 1 : 0;
$table->Media_Newspaper = isset($data->Media_Newspaper) ? 1 : 0;
$table->Media_Mail = isset($data->Media_Mail) ? 1 : 0;
$table->Media_Web = isset($data->Media_Web) ? 1 : 0;
$table->Media_Kinsmen_Member = isset($data->Media_Kinsmen_Member) ? 1 : 0;
$table->Media_Other = isset($data->Media_Other) ? 1 : 0;
$table->Radio_CJCY = isset($data->Radio_CJCY) ? 1 : 0;
$table->Radio_MY96 = isset($data->Radio_MY96) ? 1 : 0;
$table->Radio_ROCK = isset($data->Radio_ROCK) ? 1 : 0;
$table->Radio_CHAT = isset($data->Radio_CHAT) ? 1 : 0;
$table->Radio_POWER = isset($data->Radio_POWER) ? 1 : 0;
$table->Radio_Other = isset($data->Radio_Other) ? 1 : 0;
$table->agegroup = $data->agegroup;
$table->orderdate = date('Y-m-d H:i:s');
$table->ip = $_SERVER['REMOTE_ADDR'];
$table->ord_type = ($user->get('id') > 0) ? 'CallCentre' : 'online';
$table->ord_id = $ord_id;
if($data->tickets == '0') {
$table->ticket_type = 'None';
} elseif($data->tickets == '-1') {
$table->ticket_type = '3Pack';
} elseif($data->tickets == '1') {
$table->ticket_type = '1ticket';
} elseif($data->tickets == '5') {
$table->ticket_type = '8tickets';
}
if($data->fiftytickets == '0') {
$table->fiftyticket_type = 'None';
} elseif($data->fiftytickets == '1') {
$table->fiftyticket_type = '1ticket';
} elseif($data->fiftytickets == '2') {
$table->fiftyticket_type = '3tickets';
}
$table->province = 'AB';
$table->creditcard = $data->cctype;
if(isset($data->giftpurchase)) {
$table->giftname = $data->giftname;
$table->giftadress = $data->giftadress;
$table->giftcity = $data->giftcity;
$table->giftpostal = $data->giftpostal;
}
$data->ord_id = $ord_id;
$tickets = 1;
$table->qty = $data->tickets;
if($data->tickets === '-1')
{
$tickets = 3;
$table->qty = 3;
} elseif($data->tickets === '1')
{
$tickets = 1;
$table->qty = 1;
} elseif($data->tickets === '5')
{
$tickets = 8;
$table->qty = 8;
}
$threepack = '';
$i = '';
for($i = 0; $i < $tickets; $i++)
{
$firstname = 'firstname'.$threepack;
$lastname = 'lastname'.$threepack;
$address = 'address'.$threepack;
$city = 'city'.$threepack;
$postal = 'postal'.$threepack;
$phone = 'phone'.$threepack;
$altphone = 'altphone'.$threepack;
$sec_firstname = 'sec_firstname'.$threepack;
$sec_lastname = 'sec_lastname'.$threepack;
$email = 'email'.$threepack;
$table->firstname = $data->$firstname;
$table->lastname = $data->$lastname;
$table->address = $data->$address;
$table->city = $data->$city;
$table->postal = $data->$postal;
$table->phone = $data->$phone;
$table->altphone = $data->$altphone;
$table->sec_firstname = $data->$sec_firstname;
$table->sec_lastname = $data->$sec_lastname;
$table->email = $data->$email;
$table->id = 0;
if($data->tickets === '-1' || $data->tickets === '5')
{
if($threepack == 2)
{
$threepack = 3;
} else {
$threepack = 2;
}
}
}
$fiftytickets = 1;
$table->fiftyqty = $data->fiftytickets;
if($data->fiftytickets === '1')
{
$fiftytickets = 1;
$table->fiftyqty = 1;
} elseif($data->fiftytickets === '2')
{
$fiftytickets = 3;
$table->fiftyqty = 3;
}
$table->order_total = $data->total;
$table->store();
//sending confirmation mail
$mailcontent = '';
for($i = 0; $i < $data->tickets; $i++)
I have figured out the issues with the for loop. The fiftytickets code needed to be moved above the for loop and the $table->store() function needed to be moved into the for loop and placed after the $table->id line. Now when a ticket or tickets are purchased, three entries with the same name or unique names are inserted into the database.
How increase the performance of this code in php?
or any alternative method to find out the comment if the string starts with # then call at()
or if string starts with "#" then call hash()
here the sample comment is "#hash #at #####tag";
/
/this is the comment with mention,tag
function getCommentWithLinks($comment="#name #tag ###nam1 test", $pid, $img='', $savedid='', $source='', $post_facebook='', $fbCmntInfo='') {
//assign to facebook facebookComment bcz it is used to post into the fb wall
$this->facebookComment = $comment;
//split the comment based on the space
$comment = explode(" ", $comment);
//get the lenght of the splitted array
$cmnt_length = count($comment);
$store_cmnt = $tagid = '';
$this->img = $img;
$this->saveid = $savedid;//this is uspid in product saved table primary key
//$this->params = "&product=".base_url()."product/".$this->saveid;
$this->params['product'] = base_url()."product/".$this->saveid;
//$this->params['tags']='';
foreach($comment as $word) {
//check it is tag or not
//the first character must be a # and remaining all alphanumeric if any # or # is exist then it is comment
//find the length of the tag #mention
$len = strlen($word);
$cmt = $c = $tag_name = '';
$j = 0;
$istag = false;
for($i=0; $i<$len; $i++) {
$j = $i-1;
//check if the starting letter is # or not
if($word[$i] == '#') {
//insert tagname
if($istag) {
//insert $tag_name
$this->save_tag($tag_name, $pid);
$istag = false;
$tag_name = '';
}
//check for comment
if($i >= 1 && $word[$j]=='#') {
$this->store_cmnt .= $word[$i];
}else{
//append to the store_coment if the i is 1 or -1 or $word[j]!=#
$this->store_cmnt .= $word[$i];//23,#
}
}else if($word[$i]=='#') {
//insert tagname
if($istag) {
//insert $tag_name
$this->save_mention($tag_name, $pid, $fbCmntInfo);
$istag = false;
$tag_name = '';
}
//check for comment
if($i >= 1 && $word[$j]=='#') {
$this->store_cmnt .= $word[$i];
}else{
$this->store_cmnt .= $word[$i];//23,#
}
}else if( $this->alphas($word[$i]) && $i!=0){
if($tag_name=='') {
//check the length of the string
$strln=strlen($this->store_cmnt);//4
if($strln != 0) {
$c = substr($this->store_cmnt, $strln-1, $strln);//#
if($c=='#' || $c=='#') {
$this->store_cmnt = substr($this->store_cmnt, 0, $strln-1);//23,
$tag_name = $c;
}
}
//$tag_name='';
}
//check that previous is # or # other wise it is
if($c=='#' || $c=='#') {
$tag_name .= $word[$i];
$istag = true;
//check if lenis == i then add anchor tag her
if($i == $len-1) {
$istag =false;
//check if it is # or #
if($c=='#')
$this->save_tag($tag_name,$pid);
else
$this->save_mention($tag_name,$pid,$fbCmntInfo);
//$this->store_cmnt .= '<a >'. $tag_name.'</a>';
}
}else{
$this->store_cmnt .= $word[$i];
}
}else{
if($istag) {
//insert $tag_name
$this->save_tag($tag_name,$pid);
$istag = false;
$tag_name = '';
}
$this->store_cmnt .= $word[$i];
}
}
$this->store_cmnt .=" ";
}
}
Try This it may be help full
function getResultStr($data, $param1, $param2){
return $param1 != $param2?(''.$data.''):$data;
}
function parseWord($word, $symbols){
$result = $word;
$status = FALSE;
foreach($symbols as $symbol){
if(($pos = strpos($word, $symbol)) !== FALSE){
$status = TRUE;
break;
}
}
if($status){
$temp = $symFlag = '';
$result = '';
foreach(str_split($word) as $char){
//Checking whether chars are symbols(#,#)
if(in_array($char, $symbols)){
if($symFlag != ''){
$result .= getResultStr($temp, $symFlag, $temp);
}
$symFlag = $temp = $char;
} else if(ctype_alnum($char) or $char == '_'){
//accepts[0-9][A-Z][a-z] and unserscore (_)
//Checking whether Symbol already started
if($symFlag != ''){
$temp .= $char;
} else {
//Just appending the char to $result
$result .= $char;
}
} else {
//accepts all special symbols excepts #,# and _
if($symFlag != ''){
$result .= getResultStr($temp, $symFlag, $temp);
$temp = $symFlag = '';
}
$result .= $char;
}
}
$result .= getResultStr($temp, $symFlag, '');
}
return $result;
}
function parseComment($comment){
$str = '';
$symbols = array('#', '#');
foreach(explode(' ', $comment) as $word){
$result = parseWord($word, $symbols);
$str .= $result.' ';
}
return $str;
}
$str = "#Richard, #McClintock, a Latin professor at $%#Hampden_Sydney #College-in #Virginia, looked up one of the ######more obscure Latin words, #######%%#%##consectetur, from a Lorem Ipsum passage, and #going#through the cites of the word in classical literature";
echo "<br />Before Parsing : <br />".$str;
echo "<br /><br />After Parsing : <br />".parseComment($str);
use strpos or preg_match or strstr
Please refer string functions in php. You can do it in a line or two with that in built functions.
If it not matches better to write a regex.