PHP - How To Add Integer Value To Count(*) Function
How can I modify the following code to not display $hash_row['total'], but to display the sum of the counted "total" value + 1? Is there a way that I can assign that variable in the "select query" area (for instance, "COUNT(hr.hasher_id) + 1 as total1"), and then call $hash_row['total1] in the result table?
I'm not sure if the syntax exists to add an integer value to a COUNT value and assign to a new variable... Code: [Select] <?php include "modules/dbase_connection.php"; #create MySQL connection $sql_connection = sql_connect("blah","blah","blah","blah"); # select the Hashers and hashes by total number<br /> $hash_query = " SELECT ha.*, COUNT(hr.hasher_id) as total FROM hashers as ha, hash_records as hr WHERE hr.hasher_id = ha.hasher_id GROUP BY hr.hasher_id ORDER BY total DESC "; $hash_result = mysql_query($hash_query) or die(mysql_error()); $x = 1; while($hash_row = mysql_fetch_array($hash_result)) { #display the table header if($x == 1) { echo ' <br /> <table align="left"> <br /> <tbody> <tr><br /><td colspan="2"><strong>Potential On-Sec</strong></td><br /></tr>'; $x++; } echo '<tr><br /><td>' . $hash_row['hasher_name'] . '</td><br /><td>' . $hash_row['total'] . '</td><br /><td>- ' . $hash_row['real_name'] . '</td><br /></tr>'; } echo '</tbody></table></td><br />'; ?> Similar TutorialsThis is a dummy question but i cant get multiple criteria in the count function.
This is what i'm trying to do:
SELECT COUNT(Name, Expansion, Foil) AS NameCheck FROM Osiris WHERE Name="$name" Expansion="$expansion" Foil="$foil"I have Colums named: `Name` `Color` `Type` `Subtype` `Power` `Toughness` `Manacost` `Rarity` `Expansion` `Foil` `Stock`I want to check before i enter a new record if its not already there, by checking the Name, Expansion and Foil colum on the same record. I think i have just messed up that code line but i cant seem to find any solution on the web. Thanks in advance! I have no idea why but no matter what the eventid is, the label always returns 20 and I"m not sure why. Is my synatx wrong? $eventid = (int)$_GET['eventid']; $result = mysqli_query($dbc, "SELECT count(label) FROM `events` WHERE `event_id` = '$eventid'"); $label = $result + 1; echo $label; Hi, I want the user to be able to go to one page and hit a button, once he hits the butten I want a count down to start from 10 minutes. When the user goes to the page within those 10 minutes, I want it to show him a live countdown until those ten minutes run out. Any ideas how I would go about doing this? Code: [Select] function width2($noid) { $getwidth = mysql_query("SELECT * FROM block WHERE sid='$theid'",$this->connect); while($row1 = mysql_fetch_assoc($getwidth)) { $this->width2($noid); } } how do i count how many times the function loops? I am writing a function to count the words that have been typed into a text box. I originally had it working when I first wrote it but it was counting all of the punctuation as a word so I I tried adding some code to eliminate that. Now it is not working. Could someone help me? Here is my code Code: [Select] function count_words($description){ $word_count = 0; $description = trim(preg_replace("/\s+/"," ",$description)); $word_array = explode(" ", $description); for($i=0; $i < count($word_array); $i++){ if (preg_match("[0-9A-Za-z]", $word_array[$i])) { $word_count++; } return $word_count; } } Write a function Counter() that keeps track of the number of times it is called. This function should not take any parameters and return the number of times that it has been called. I know there has to be a better way to count how many entries I have in my mysql db than what I'm currently using. Let me just show you what I'm trying to do and it will make better sense. http://batads.com/display.php You see how I am echoing the number of each category on one page? I am sure the current script I am using is insanely inefficient and as my DB grows I think it will cause me problems. Any suggestions on how to do this more efficiently? Below is what is currently running that page. Thank you. Code: [Select] <td><h4>Public Ads</h4><br> <?php echo '<a href="browse1.php?cat=1">Bill Boards<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='1'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=2">Transportation<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='2'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=4">Shopping Centers<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='4'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=3">Posters / Signs<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='3'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=5">Bus Stops<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='5'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=6"> Other-Public<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='6'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Event Sponsorship</h4><br> <?php echo '<a href="browse1.php?cat=7">Concerts<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='7'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=8">Fairs<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='8'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=10">Sports<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='10'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=9">Trade Shows<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='9'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=11">Other-Event<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='11'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Online Ads</h4><br> <?php echo '<a href="browse1.php?cat=12">Banner Space<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='12' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=13">Social Media<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='13' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=14">Email Lists<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='14'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=15">Blog Articles<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='15'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=16">Ezine Articles<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='16'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1area.php?cat=17">Other-Online<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='17'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </tr> <tr> <td><h4>Print Ads</h4><br> <?php echo '<a href="browse1.php?cat=18">Magazine<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='18'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=19">Newspaper<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='19'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=20">Brochure<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='20'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=21">Press Release Print<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='21'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=22">Other-Print<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='22'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Broadcasting Ads</h4><br> <?php echo '<a href="browse1.php?cat=23">TV / Commercial<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='23'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=24">Radio<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='24'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=27">Movies<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='27'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=25">Mobile Phone<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='25'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=28">Cinema<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='28'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=26">Press Release TV<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='26'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=29">Other-Broadcast<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='29' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Commercial Space</h4><br> <?php echo '<a href="browse1.php?cat=33">Private Property<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='33'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=34">Vehicle Wrap<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='34'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=35">Front Yard<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='35'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=36">Self Promotion<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='36'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=37">Other-Commercial<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='37'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </tr> <tr> <td><h4>Business Ads</h4><br> <?php echo '<a href="browse1.php?cat=30">Window Display<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='30'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=31">Interior Ads<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='31'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=32">Point of Sale Ads<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='32'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=41">Other-Business <a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='41'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </td> <td><h4>Misc</h4><br> <?php echo '<a href="browse1.php?cat=38">Creative Advertising<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='38'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=39">Video Games<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='39'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=40">Other-Misc<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='40'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> </td> </tr> </table> Hi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; Anyone can help me? <?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles I want to round off an integer vaule to 10-6 grd from 52.71666666 to 52716666 0.926888888 to 926888 does anyone know a simple way to do this? 0 down vote favorite Hi Guys! I have a method that get's all devices that share a specific ID. Foreach of those device UID's, I am trying to send a APN (Apple Push Notification) using the easyAPN's class. The method that is having the problem is $apns->newMessage($id); It seems to think I am not passing a valid integer for $id. The $id is an array like so Array ( => 1 ) I have also tried passing just the value of the array like so $apns->newMessage($id[0]). No matter what I do.. I keep getting this error... "Notice: TO id was not an integer. 1) Messages_model::send_apns -> File: sendMessage.php (line 28) 2) APNS::queueMessage -> File: messages_model.php (line 195) 3) APNS::_triggerError -> File: class_APNS.php (line 599)" Here is my method... please let me know where I've gone wrong with the $id. function send_apns($data) { include 'apn_classes/class_DbConnect.php'; include 'apn_classes/class_APNS.php'; $message = new Messages_model(); $db = new DbConnect(); $db->show_errors(); $apns = new APNS($db); //get uid's for aid $sql = "SELECT `devices`.`uid` FROM `devices` WHERE `devices`.`aid` = '".$data['target']."'"; //echo $sql; $query = mysql_query($sql); if(mysql_num_rows($query)) { while($uid_data = mysql_fetch_array($query)) $uids[] = array( "uid" => $uid_data['uid'] ); } //make sure there is a uid if(!empty($uids)) { //check the device apn pid foreach($uids as $uid) { $sql = "SELECT `apns_devices`.`pid` FROM `apns_devices` WHERE `apns_devices`.`deviceuid` = '".$uid['uid']."'"; //echo "$sql"; $query = mysql_query($sql); if(mysql_num_rows($query) > 0) { while($pid_data = mysql_fetch_array($query)) { $pids[] = array( "pid" => $pid_data['pid'], ); if(!empty($pids)) { foreach ($pids as $pid) { $id = array($pid['pid']); print_r($id); //Send APN $apns->newMessage($id[0]); $apns->addMessageBadge(128); $apns->addMessageAlert($data['message']); $apns->addMessageSound('chime'); //$apns->addMessageCustom('acme2'); $apns->queueMessage(); $apns->processQueue(); } } } } } } else { echo "Device Does not Exist"; } } Hi i'm trying to get out a sub string from multiple pages where i'm using a start point string that looks like this "(integer)" where "integer is different every time. Is there any way I can tell it that its just an integer there so if its "(3)" on one page and "(10)" on another page it will start from the same spot? Hey, I have this brainstorm whether I should store id's as integers or text? I mean in my database, since my IDs start from like 1319129364 which is a rather large number, I was thinking if it would be better to save it as text? Which case requires less memory ? So I am trying to take a string value of dollars (posted from a form) and times it by 100 to get the cents Integer value of the dollars. For some reason if I do this with something like 278.53 I end up with 27852. Same concept for 278.59 ends up as 27858. I don't understand why or how to make it work. I've tried many things and nothing has made it work. $price = '278.53'; // posted from the form $cents = $price * 100; // converting to cents. end_result = (int)$cents // This will end up being 27852 not 27853.
Ive got a simple function that's counting percentages of the results, and what I want is when the first line does $variable / 100 - to go on 2 decimals(ex. 0.72142141 what I want is to write 0.72). Code: [Select] function postotak(){ $p = $bodovi / 100; $postotak = $p * 100; Hi, not sure if this is posted in the right place (think it should be in the Regex section ) but hopefully someone can help me out a bit. I have the following string for example which is stored in a variable called $var. Quote This is a reference [ref=17][/ref] number I wish to extract only the number after the equals sign and store it as a variable. So I am using the following code to do so: $ref_num = preg_replace("/.*?\[ref\=(.*?)\]\[\/ref\].*?/is", "$1", $var); The only problem is, I can omit the text before the integer and the tags themselves but I still get the text after the [/ref] section and I cannot get rid of it. It seems my .*? placed after it doesn't work like it does at the beginning. Can anyone offer any help at all, it will be greatly appreciated - I'm fairly new to using Preg_replace so I still don't know how best to form Regular Expressions. Thanks, Dan EDIT- I have found a workaround which I will post below - however I would still like to solve it the way I planned originally which is the way I posted here. Here's what I did - because I know the integer is never going to be more than 5 characters long, I used the replace from before but added a substring like so. $ref = substr(preg_replace("/.*?\[ref\=(.*?)\]\[\/ref\]/is", "$1", $var),0,5); This grabbed the first 5 characters whether it was a number or not, then I used this to strip any non-numerical characters. Finally I added an intval to convert it to an integer rather than a string. $ref = intval(preg_replace ('/[^\d\s]/', '', $ref)); |