ShawnCplus 456 Code Monkey Team Colleague

Good day.
I want to create a small app that would take out the content from a rss feed and posteriorly from the url .
I know that would be easily done in perl with regular expressions, but in php it seams a bit more difficult.
So i want to translate the next querry from perl to php :

$mystring="startABCend";
if($mystring =~ m/start(.*)end/) {
	print $1;
}

Basically what it does is selecting any string from the middle of the string, so it would show "ABC".
Thanks in advance.

http://php.net/preg_match

$string = 'startABCend';
if (preg_match('/start(.*)end/', $string, $matches)) {
  echo $matches[1];
}
ShawnCplus 456 Code Monkey Team Colleague

Hmm, have you seen sprintf or does this serve a different purpose? This could be great if the function took, say, a callback function that could be used to validate fields that were passed to it.

ShawnCplus 456 Code Monkey Team Colleague

I would suggest that you think of a way to make it a bit more secure than simply posting any email you get to the web but if that's what you want to do IMAP is probably the way to go. http://php.net/imap

ShawnCplus 456 Code Monkey Team Colleague

hi,

my string is
$string="Sign up for Facebook to connect with Jean Profession";

i want to find word randomly from string

like :- connect or Profession whose length >4 and this word not is a facebook.

Yes, you described that, which is why I posted a link describing how to do it.

ShawnCplus 456 Code Monkey Team Colleague
ShawnCplus 456 Code Monkey Team Colleague

Here's a hint: You want to use both. The PHP shouldn't be a "backup" since you can't trust client-side validation. Client-side validation is nice to give users some feedback but it can also be malicious.

ShawnCplus 456 Code Monkey Team Colleague

PHP Directory functions, the examples are in there: http://php.net/dir

ShawnCplus 456 Code Monkey Team Colleague
<?php
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=trim($_POST['searchterm']);
if (!$searchtype || !$searchterm) {
	echo 'You have not entered search details.';
	exit;
}
if (!get_magic_quotes_gpc()){
	$searchtype = addslashes($searchtype);
	$searchterm = addslashes($searchterm);
}
$db = new mysqli('localhost', 'username', 'password', 'database');
if (mysqli_connect_errno()) {
	echo 'Error: Could not connect to database. Please try again later.';
	exit;
}
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
if ($num_results) { // add this
	for ($i=0; $i <$num_results; $i++) {
		$row = $result->fetch_assoc();
		echo "<div class='mess'><strong>";
		echo htmlspecialchars(stripslashes($row['title']));
		echo "</br></strong><br /><strong>Found:</strong> </br></div>";
		echo stripslashes($row['author']);
	}
} else { // and this
	echo 'There were no results found.'; // stuff
} // here
$db->close();
?>
ShawnCplus 456 Code Monkey Team Colleague

You won't be able to change the style of alert() windows since the browser decides what they look like. You could, however, create your own modal dialogs using lightboxes. Google around for lightbox or thickbox. http://jquery.com/demo/thickbox/

ShawnCplus 456 Code Monkey Team Colleague

Tomcat is traditionally used for Java, not for PHP. WAMP was made to be a turnkey PHP server

ShawnCplus 456 Code Monkey Team Colleague
ShawnCplus 456 Code Monkey Team Colleague

Where you have mysql_query($sql_updt) or die(mysql_error()); put echo $sql_updt; and paste the the output here

ShawnCplus 456 Code Monkey Team Colleague
$TeacherInterrupts = true;
$counter = 1;
while ($counter < 11) {
print(" counter = " + $counter + "<BR>");
if ($TeacherInterrupts = = true) break;
$counter++;
}

Dear concern I want to know the "+$counter+" meaning and

I am also getting the parse error on line #4

please guide me about this

The parse error is because of the +'s, .'s are used for concatenation in PHP (joining strings together)

$TeacherInterrupts = true;
$counter = 1;
while ($counter < 11) {
  print(" counter = " . $counter . "<BR>");
  if ($TeacherInterrupts == true) break;
  $counter++;
}
ShawnCplus 456 Code Monkey Team Colleague

Remove the .. in front of /usr

ShawnCplus 456 Code Monkey Team Colleague

You would use the function just like you would inside another function. With the example code afunction isn't defined (there is no prototype.) You could do something like this

void afunction(); // function prototype

class example {
    public:
    example();
    ~example();
    
    void doSomthing() {
        afunction();
    }

};

void afunction() {
    //do more things
}
ShawnCplus 456 Code Monkey Team Colleague

Then just get the absolute positions of both then subtract the item you want's position from the item that it's relative from.

Box1 : x 100, y 200
Box2 : x 234, y 123
Box2 Relative Box1: x 134, y -77
ShawnCplus 456 Code Monkey Team Colleague

Daniweb on proggit!

ShawnCplus 456 Code Monkey Team Colleague

Congrats for making slashdot!

ShawnCplus 456 Code Monkey Team Colleague

Well, my opinion, which is probably insanely misguided is that it is much like the magnetic charge on a floppy disk's magnetic tape. Which would take a bit more than a fridge magnet to wipe it out but then again memory is exponentially more volatile then the aforementioned floppy disk. Also, I've taken a look at the structure of the chips and it is an amazing idea, however it looks extremely, for lack of a better word, fragile and susceptable to damage from the slightest bumps and the magnetic charges albeit extremley small could perhaps interfere. As I said my opinion is perhaps very misguided and the developers/inventors have without a doubt thought of every point I have put across here and although my opinion is a little pessimistic, I do hope that MRAM will be the future.

ShawnCplus 456 Code Monkey Team Colleague

Actually there is a standard method to do this using C++ string streams

int some_int = 10;
stringstream some_stream;
some_stream << some_int;
string some_string = some_stream.str();
ShawnCplus 456 Code Monkey Team Colleague

well that notwithstanding this is also completely useless as sed can. already do it :)

sed -n 10,15p file
ShawnCplus 456 Code Monkey Team Colleague

I ran across the need to view a specific line of a file so I wrote this up. You can view a line or a range of lines for a file or compare two files. Check the command for the syntax. Drop it in /usr/bin/sln and enjoy.

ShawnCplus 456 Code Monkey Team Colleague

So you've got this big long function chain and PHP's oh-so-helpful Fatal Error messages aren't helping at all. Here's a quick example of how to do a function backtrace without throwing exceptions.

Output:

=>[0] => Array
  (
    [file] => someFile.php
    [line] => 4
  )
=> Hello World
ShawnCplus 456 Code Monkey Team Colleague

Small addition, in the argument list, if you change $total to $total=null Then right before if(count... you add the following

if($total == 0 || $total == null){
    foreach($data as $key=>$value){
      $total += $value;
    }
  }

You no longer have to pass a total since it will just do it for you. (small oversight on my part not to add it in the first place)

ShawnCplus 456 Code Monkey Team Colleague

This is a recursive function I made to draw purely CSS bar graphs. You pass it an array of data and the total amount, example:

$someData = array('Oranges'=>4, 'Apples'=>10);
$total = 14;
echo drawCSSGraph($someData, $total);

Also, you can pass it options in the form of an array or as space separated couples, exa:

//perfectly fine
echo drawCSSGraph($data, $total, 'height=20 width=300 color=#c0c0c0');
//works just as well
$options = array('height'=>20, 'width'=>300, 'color'=>'#c0c0c0');
echo drawCSSGraph($data, $total, $options);

Also, you can put [var] in the label which will be parsed out when the graph is drawn

$data = array('Data1: [var]'=>20, 'Data2: [var]'=>19);
echo drawCSSGraph($data, 39);
==>
    Data1: 20
    [graph here]
    Data2: 19
    [graph here]

It will detect whether you're making a vertical or horizontal bar graph and adjust accordingly. If you want it vertical just make the height greater than the width.

ShawnCplus 456 Code Monkey Team Colleague

I think you mean capitalize. If you capitolize it you turn it into money. I wasn't aware PHP was the philosopher's stone of the 21st century

ShawnCplus 456 Code Monkey Team Colleague

This is about as simple as it gets with menu generators. Everything is explained in the code. Note that the menu is simply an unordered list so to pretty it up it really relies on the CSS.

If you don't want to write any CSS of your own here is a sample stylesheet.

#Menu 
{
	position:absolute;
	width:95%;
	height:44px;
	z-index:3;
	left: 4px;
	top: 175px;
} .tabbedmenu
{
    padding: 3px 0;
    margin-left: 0;                
    font: bold 12px Verdana;
    border-bottom: 2px groove #F16C0A;
    list-style-type: none;
    text-align: left;
}
.tabbedmenu ul 
{
    margin: 0;
    padding: 0;
    float: left;
}
.tabbedmenu li
{
    display: inline;
    position: relative;
    margin: 0;
}
.tabbedmenu li li{display: block;}
.tabbed menu li li:hover{display: inline;}

.tabbedmenu li a
{
    text-decoration: none;
    padding: 3px 7px;
    margin-right: 3px;
    border: 3px double gray;
    border-bottom: none;
    background-color: #000000;
    color: #FFFFFF;
}    
.tabbedmenu li a:hover
{
    background-color: #F16C0A;
    color: black;
}
.tabbedmenu li a:active {color: #FFFFFF;}
.tabbedmenu li a.selected
{
    position: relative;
    top: 1px;
    padding-top: 4px;
    background-color: #F16C0A;
    color: white;
}
ShawnCplus 456 Code Monkey Team Colleague

A caeser cypher with a shift of 13 is known as ROT13 just incase you didn't know that and it's the easiest cypher I know of to code besides an XOR

ShawnCplus 456 Code Monkey Team Colleague

If your function is defined above main you don't need the prototype.

ShawnCplus 456 Code Monkey Team Colleague

It should be int main(void) and lines 12 and 15 will cause errors due to a missing " at the beginning of the string.

ShawnCplus 456 Code Monkey Team Colleague

It is true '\0' means the end of a string but that is because it is the ASCII NULL code. A string can contain an '\0' before the actual end of the array though nothing after it will be seen when printing the string and there will be another NULL character at the end of the array.
In C++ char arrays this character is implied when creating an array.

Please correct me if I am wrong.

ShawnCplus 456 Code Monkey Team Colleague

This program was inspired by my college math 1 class. It takes the values of a1, a2, b1, b2, c1, c2 and solves, displays the equation and shows the work. It also stops if the equation is dependant or inconsistent (Zero division)
Cramer's Rule
if a1x+b1y=c1 and a2x+b2y=c2

then x=((c1*b2)-(c2*b1))/((a1*b2)-(a2*b1))
y=((a1*c2)-(a2*c1))/((a1*b2)-(a2*b1))

where (a1*b2)-(a2*b1)!=0

#Compiled on Dev-C++

#Comment or post bugs please

ShawnCplus 456 Code Monkey Team Colleague

sorry mautd, when I wrote this program I had no formal experience my entire knowledge of C++ was based off tutorials. and there was no real reason to make it portable, if you are speaking of linux then just include the cstdlib header and replace "cls" with "clear".
As to A.FATHA I'm glad I could help.

ShawnCplus 456 Code Monkey Team Colleague

sorry for the overlapping text, and despite the look here, the big blocky things do actually look like a lane with bowling pins in a console window

ShawnCplus 456 Code Monkey Team Colleague

I created a bowling game, Which for the most part works correctly. I toiled for hours trying to figure out how to do the scoring so i gave up. Its fairly simple code so not much of a description needed.

ShawnCplus 456 Code Monkey Team Colleague

Well its fairly self explanatory, its a program that shows that calculates the hypotenuse using the pythagorean theorum, It displays the values of the sides and shows a crappy ascii art right triangle with the values input and the later found values

ShawnCplus 456 Code Monkey Team Colleague

Ok I greatly modified a tutorial to have a completely different interface, a highscore list and a little tiny really rare easter egg.
to get the highscore list. I want to figure out how to sort the highscore list if it is possible. And dont worry about it freaking out, if you type a letter instead of a number it will yell at you basically, it will stop the program and tell you what the random number was and have you quit the program. If you dont guess the number in time your name is not added to the list. (Dev-C++)

ShawnCplus 456 Code Monkey Team Colleague

I have a little question in my line of code that asks for a name how do i add an exception for the name like if (name==blah) it tells me that blah is undefined.

ShawnCplus 456 Code Monkey Team Colleague

Sorry for all the comments most of them are for me so incase i get stupid and forget one of those lines, a little mental
helper, and yes before anyone asks and wastes a post i am in school why else would i make this :)

ShawnCplus 456 Code Monkey Team Colleague

This is the first program I wrote, well besides Hello world. I put about a lot of hours into this code, it started as a divisional calculator than i evolved it so it would ask your name and calculate your average and i was messing around with the system ("") code to manipulate it to change the text and background color, you can change it if you want just go Start>Run>cmd>help colors> then where the colors are enter it in the system("color blah") well hope it works and i hope you like it

ShawnCplus 456 Code Monkey Team Colleague

system ("cls") and other system commands are handy to get a list of all possible system lines that i know of just go Start>run>cmd>help, it gives a list of all commands that you could use some usefull ones are color ie.
system("color A")
would change the text on the console to bright green (hello matrix)

ShawnCplus 456 Code Monkey Team Colleague

Did you get the idea from the console command, IF EXIST?

ShawnCplus 456 Code Monkey Team Colleague

Well you have an unclosed/broken tag here on line 62 that may be causing issues

<div <!--Div class added by Damion -->

Aside from that grab firebug(http://getfirebug.com) for firefox and toy around with the CSS until you get it where you want it then just copy into your file.

ShawnCplus 456 Code Monkey Team Colleague

*nod* as the php documentation(php.net/mysql_pconnect) states, the host is in the form of hostname:port

ShawnCplus 456 Code Monkey Team Colleague

Your php configuration probably has error_reporting set to 0, set it to 30719 and you'll start seeing errors instead of white screens

ShawnCplus 456 Code Monkey Team Colleague
require "dbconn.php";
$id=$_POST['id'];
$checkquery = "SELECT * FROM table WHERE id = '$id'";
$checkresults = mysql_query($checkquery);
var_dump($checkresults);
die();
$row = mysql_fetch_row ($checkresults);

Do that and post the output

ShawnCplus 456 Code Monkey Team Colleague

You might want to use google before we spoonfeed you homework help.

ShawnCplus 456 Code Monkey Team Colleague

Take a look at the FAQ that is stickied, follow those instructions and then if it still doesn't work repost your code along with the new errors

ShawnCplus 456 Code Monkey Team Colleague

Hi,
I think i am missing something obvious. The popup should bring up a page passing an id. Currently nothing happens but i can see the id is being passed into the varaiable when hovering over Link, how can this be chnaged. Below is part of the code

thanks

A) This isn't your first post, use code tags

B) You need to escape your quotes

while($row = mysql_fetch_assoc($result)) {
echo
'<tr>
	<td>'.$row['image'].'</td>				<td>'.$row['id'].'</td>
	<td><a href="javascript:window.open(\'newpage.php?src=' .$row['id']. '\' ,\'\',\'resizeable=1,width=400,height=400,top=100,left=100\');">Link</a></td>
</tr>';
}
echo "</table>";
ShawnCplus 456 Code Monkey Team Colleague

Javascript strings don't have a trim function, to add one you can do something like

String.prototype.trim = function ()
{
  return this.replace(/^\s+|\s+$/, '');
};

somevar = "I have a string with trailing spaces       ";
somevar_trimmed = somevar.trim(); // "I have a string with trailing spaces"

// So yours will be
parent.TopFrame.document.FormName.inputAreaName.value = tableName.rows[1].cells[0].innerHTML.trim();