473,394 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

special char + eregi()

Ive searched, and ive seen many tutorials but i must not be getting it. Ive tried using brackets, ive tried using escape chars but nothing is working. Perhaps im just using them in wrong order, but right now ive got everything twisted. How do i determine or find the '+' inside a string for example "2+2="?

else if(eregi( '+' , $q ))
{
$a = sscanf($q, "%d+%d=", $num1, $num2);
$answer = ($num1 + $num2);
$response = $answer;
}

thanks for any help given
Sep 26 '06 #1
1 1563
ronverdonk
4,258 Expert 4TB
You can use the split() function, as follows:
[PHP]
$exp="2 + 2";
list($num1, $num2) = split('[+]', $exp);
$answer = $num1+$num2;
echo "answer = $answer<br />";[/PHP]

Ronald :cool:
Sep 27 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: fartsniff | last post by:
Hello all. I am starting to work on a URL "cleaner" of sorts. The code below is only checking for a few simple entries on the URL, but for some reason it is not replacing them with "" when...
1
by: Ralph Freshour | last post by:
Can someone please tell me why this function always evaluates to true regardless of what I enter? Thanks... if (!eregi ("A-Za-z", $frm_member_name)) { // invalid characters...
5
by: Jane Doe | last post by:
Hi I took a quick look in the archives, but didn't find an answer to this one. I'd like to display a list of HTML files in a directory, showing the author's name between brackets after the...
5
by: george | last post by:
(driving me nuts) Hi there. I wonder if anyone can help? I'm including a page from Google in search.php, passing some parameters. So far so good. Then I'm asking to look through that Google...
2
by: Frank | last post by:
I'm having trouble detecting whitespaces in strings. Set up this test: echo "<br>example 1:".intval(eregi("^\s","teststring")); echo "<br>example 2:".intval(eregi("^\s","test string")); ...
25
by: Dynamo | last post by:
Hi The following script was taken from John Coggeshall's (PHP consultant) in his article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php // Get the email address to validate...
1
by: news | last post by:
God, I have read every comment in php.net eregi and Google searched, and I have tried so many different attempts...this is the closest I've gotten to verify a variable contains only:...
4
by: Nel | last post by:
Hi all, I am struggling with understanding a small eregi problem in php4. My code: <?PHP $htmlsource = '<img src="pics/hotdog.gif"> text text <img src="pics/silly%20sausage.gif"> ';...
1
by: fade2gray | last post by:
Hi, (new to group and a php novice) I'm editing some files using exapmles for reference. (1) // if (!eregi("admin.php", $_SERVER)) { die ("Access Denied"); } (2) if ( !defined('ADMIN_FILE')...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.