techno surprises

September 4, 2008

C# source code for strip_tags in PHP

Filed under: c, c sharp, csharp, php, strip_tags — Tags: , , , , , , , — Mustafa Turan @ 11:52 pm

Source to download: http://mustafaturan.net/download/lectures/csharp/strip_tags_csharp.txt

// as a namespace do not forget to add: using System.Text.RegularExpressions;
static string strip_tags(string str, string allowed_tags)
{
/*
// Coder: Mustafa Turan
// Date: 05.09.2008
// Contact:
// http://mustafaturan.net/
// https://mustafaturan.wordpress.com/
// wm [ #at# ] mustafaturan.net
// Licence: GNU and MIT Licence
// EXAMPLES
// —>     function call1: strip_tags(“<a href=\”asdadsadsad.html\”>doctor</a> <p>pirasa</p> <img src=\”asd.jpg\” /> <h1>hey you</h1>”, “<a>,<p>,<img />”)
// —>     result: <a href=””>doctor</a> <p>pirasa</p> <img src=”asd.jpg” /> hey you
// —>     function call2: strip_tags(“<a href=\”asdadsadsad.html\”>doctor</a> <p>pirasa</p> <img src=\”asd.jpg\” /> <h1>hey you</h1>”, “”)
// —>     result: doctor pirasa hey you
*/

// START
// pattern for getting all tags
string pattern_for_all_tags = “</?[^><]+>”;

// pattern for allowed tags
string allowed_patterns = “”;
if(allowed_tags!=””){
// get allowed tags if any exists
Regex r = new Regex(“[\\/<> ]+”);
allowed_tags = r.Replace(allowed_tags,””);
string[] allowed_tags_array = allowed_tags.Split(‘,’);
foreach (string s in allowed_tags_array)
{
if (s == “”) continue;
// Definin patterns
string p_1 = “<” + s + ” [^><]*>$”;
string p_2 = “<” + s + “>”;
string p_3 = “</” + s + “>”;
if(allowed_patterns!=””)
allowed_patterns += “|”;
allowed_patterns += p_1 + “|” + p_2 + “|” + p_3;
}
}

// Get all html tags included on string
Regex strip_tags = new Regex(pattern_for_all_tags);
MatchCollection all_tags_matched = strip_tags.Matches(str);

if (allowed_patterns != “”)
foreach (Match m in all_tags_matched)
{
Regex r_1 = new Regex(allowed_patterns);
Match m_1 = r_1.Match(m.Value);
if (!m_1.Success)
{
// if not allowed replace it
str = str.Replace(m.Value, “”);
}
}
else
// if not allow anyone replace all
str = strip_tags.Replace(str, “”);
return str;
}

May 5, 2008

mysql 5 procedure calls for creating member registration

Filed under: database, mysql 5, procedure calls — Tags: , , , , — Mustafa Turan @ 7:57 pm

http://mustafaturan.net/tr/mysql5_procedured_function_calls2_for_membership.html

## Coder Mustafa Turan ##
## http://mustafaturan.net/ ##
## Delimiters $$ ##

## members(m_ID, m_name, m_email, m_pass, m_acode, m_status, m_datetime) ##

DROP PROCEDURE NewMember$$

CREATE PROCEDURE NewMember(# yeni kullanıcı #
IN N_m_name VARCHAR(14),
IN N_m_email VARCHAR(55),
IN N_m_pass CHAR(32),
IN N_m_acode CHAR(6),
OUT N_m_err TINYINT
)
BEGIN
DECLARE name_exist TINYINT;
DECLARE email_exist TINYINT;
SET name_exist = 0;
SET email_exist = 0;

# get m_ID to name_exist #
SELECT count(m_ID) INTO name_exist FROM members WHERE m_name = N_m_name LIMIT 0,1;

# get m_ID to email_exist #
SELECT count(m_ID) INTO email_exist FROM members WHERE m_email = N_m_email LIMIT 0,1;

IF name_exist > 0 THEN
SET N_m_err = 1;
ELSE IF email_exist > 0 THEN
SET N_m_err = 2;
ELSE
INSERT INTO members (m_ID, m_name, m_email, m_pass, m_acode, m_status, m_datetime) VALUES (NULL, N_m_name, N_m_email, N_m_pass, N_m_acode, 0, NOW())
SET N_m_err = 0;
END IF;
END$$

DROP PROCEDURE ActivateMember$$

CREATE PROCEDURE ActivateMember(# kullanıcıyı aktive etmek #
IN N_m_email VARCHAR(55),
IN N_m_acode CHAR(6),
OUT N_m_err TINYINT
)
BEGIN
DECLARE already_active TINYINT;
DECLARE wrong_code TINYINT;
SET already_active = 0;
SET wrong_code = 0;

# get active status #
SELECT count(m_ID) INTO already_active FROM members WHERE m_email = N_m_email AND m_acode = N_m_acode AND m_status = 1 LIMIT 0,1;

# get code status #
SELECT count(m_ID) INTO wrong_code FROM members WHERE m_email = N_m_email AND m_acode = N_m_acode LIMIT 0,1;

IF already_active > 0 THEN
SET N_m_err = 3;
ELSE IF wrong_code <= 0 THEN
SET N_m_err = 4;
ELSE
UPDATE members SET m_status = 1 WHERE m_email = N_m_email AND m_acode = N_m_acode LIMIT 1;
END IF;
END$$

DROP PROCEDURE ChangePassword$$

CREATE PROCEDURE ChangePassword( # şifre değiştirme #
IN N_m_email VARCHAR(55),
IN N_m_pass CHAR(32),
IN O_m_pass CHAR(32),
OUT N_m_err TINYINT
)
BEGIN
DECLARE wrong_pass TINYINT;
SET wrong_pass = 0;

# get code status #
SELECT count(m_ID) INTO wrong_pass FROM members WHERE m_email = N_m_email AND m_pass = O_m_pass LIMIT 0,1;

IF wrong_pass 0 THEN
# DELETE * FROM files WHERE m_ID = O_m_ID; #
# DELETE * FROM members WHERE m_ID = O_m_ID LIMIT 1; #
UPDATE MEMBERS SET m_status = 0 WHERE m_ID = O_m_ID LIMIT 1;
SET N_m_err = 5;
ELSE
SET N_m_err = 6;

END$$


$N_m_err[0] = ‘Please check your email’;
$N_m_err[1] = ‘Already in use.’;
$N_m_err[2] = ‘E-mail in use.’;
$N_m_err[3] = ‘Already active user.’;
$N_m_err[4] = ‘Invalid activation code!’;

$N_m_err[5] = ‘User and its db files are deleted.’;
$N_m_err[6] = ‘User not found.’;

$N_m_err[7] = ‘Old password is wrong.’;

March 19, 2008

Windows Vista SP1 Download

Filed under: service pack, sp1, vista, windows — Tags: , , , , , , , , — Mustafa Turan @ 12:12 am

Microsoft published windows vista sp1 today. Here is legal download links:

Overview of Windows Vista SP1 and Download Links

http://www.microsoft.com/downloads/details.aspx?familyid=39B802EA-B2CF-4585-8CEA-2CC6A6247CB3&displaylang=en

http://msdn2.microsoft.com/en-us/windowsvista/bb898842.aspx (subscription links)

http://www.microsoft.com/downloads/details.aspx?familyid=b0c7136d-5ebb-413b-89c9-cb3d06d12674&displaylang=en

January 24, 2008

Translator Live Communication

After Google Translate Live.com published a beta  translator service which is using the  systransoft technology.

Link: http://translator.live.com/

Technology: http://www.systransoft.com/

HTML 5

Filed under: html, html 5, w3, w3.org, w3c — Mustafa Turan @ 3:13 pm

W3C Publishes HTML 5 Draft, Future of Web Content

2008-01-22: W3C today published an early draft of HTML 5, a major revision of the markup language for the Web. The HTML Working Group is creating HTML 5 to be the open, royalty-free specification for rich Web content and Web applications. “HTML is of course a very important standard,” said Tim Berners-Lee, author of the first version of HTML and W3C Director. “I am glad to see that the community of developers, including browser vendors, is working together to create the best possible path for the Web.” New features include APIs for drawing two-dimensional graphics and ways to embed and control audio and video content. HTML 5 helps to improve interoperability and reduce software costs by giving precise rules not only about how to handle all correct HTML documents but also how to recover from errors.

Source: http://www.w3.org/TR/2008/WD-html5-20080122/

January 23, 2008

PHP – MSSQL to XML

Filed under: code, column, connect, connection string, mssql, name, php, php mssql, row, sample, software, xml — Mustafa Turan @ 4:04 pm

These piece of PHP code is help to understand;

  • How to get column names from MSSQL with PHP?
  • How to get related row attributes from MSSQL with PHP?
  • And how to convert MSSQL tables to XML data store type?

Here is the source code, it is completely free and usable for any purposes.

<?php

// Coder Mustafa Turan

// https://mustafaturan.wordpress.com/
// get query from URL
$query    = urldecode($_GET[‘q’]);
if(empty($_GET[‘q’])) exit();
echo “<?xml version=\”1.0\” encoding=\”UTF-8\”?>”;
    /*
    sample query:
    $query = “SELECT * FROM table_name”;
    */

    // connection open to MSSQL
    $link = mssql_connect(‘hostname’, ‘username’, ‘password’);
    mssql_select_db(‘dbname’, $link);

    // get the query result
    $result = mssql_query($query, $link);
    $i = 0;

    // get all columns readed from query
    while ($column = mssql_fetch_field ($result)){
        $columnx[$i] = $column->name;
        $i++;
    }
    $column = null;

    // read all rows with its column name
    while (($row = mssql_fetch_array($result, MSSQL_BOTH)))
    {
        echo “\n <new_row>”;
        foreach($columnx as $C){
            // $C                : column name
            // $row[$C]            : it give the current rows’ column variable
            // sample output    : <column_name>column_content</column_name>
            echo “\n  <” . $C . “>” . $row[$C] . “</” . $C . “>”;
        }
        echo “\n </new_row>”;
    }

    // close the current connection
    mssql_free_result($result);
    mssql_close($link);
echo “\n</xml>”;
?>

December 30, 2007

Windows XP Service Pack 3 Release Candidate

Standalone Update Package for Windows® XP Service Pack 3 Release Candidate

See the overview from http://www.microsoft.com/

Windows XP SP3 combines all previously released performance, security, and stability updates. It also
provides a limited number of new and enhanced functionalities, although it does not significantly change the
Windows XP experience or bring functionality from newer versions of Windows to Windows XP. The goals of
Windows XP SP3 are to:

  • Provide a new baseline for customers still deploying Windows XP, to help them avoid the inconvenience
    of applying individual updates.
  • Fill gaps in the updates users might have missed by declining individual updates when using Automatic
    Updates, and to deliver updates not made available through Windows Update.

Windows Vista provides the most advanced security and management capability, but for PCs that cannot be
upgraded to Windows Vista right now, Windows XP SP3 ensures these PCs have all available updates and
allows these PCs to leverage some new Windows Server 2008 capabilities, such as Network Access
Protection (NAP).

All language supported downlod links:

http://www.microsoft.com/downloads/details.aspx?FamilyID=75ed934c-8423-4386-ad98-36b124a720aa&DisplayLang=en

Overview

http://www.microsoft.com/downloads/details.aspx?FamilyID=68c48dad-bc34-40be-8d85-6bb4f56f5110&DisplayLang=en#filelist

December 6, 2007

Random Team Matching with php

Filed under: php, programming — Tags: , , , , , , , , , , , — Mustafa Turan @ 5:26 pm

echo "start\n\n"; $a1 = Array('Chealsea', 'Arsenal', 'Manchester', 'Liverpool');$a2 = Array('Ato', 'Ozi', 'Mustafa', 'Emo');
$b = "0123";

$c = "0123";   for($i=0;$i<(sizeof($a1)-1);$i++) {

if($i!=0){

$b	= str_replace($s1,"",$b);

$c	= str_replace($s2,"",$c);

}

$s1	= substr(str_shuffle($b), 0, 1);

$s2	= substr(str_shuffle($c), 0, 1);

echo $a1[$s1] . ":" . $a2[$s2] . "\n";

}

echo "\n\nend";

Microsoft Visual Studio 2008 Express Edition DVD iso

Free DVD iso link given by originally download.microsoft.com

visual studio 2008 express edition all in one

http://go.microsoft.com/fwlink/?LinkId=104679

http://download.microsoft.com/download/8/B/5/8B5804AD-4990-40D0-A6AA-CE894CBBB3DC/VS2008ExpressENUX1397868.iso

Visual Basic 2008 Express Edition
Visual C# 2008 Express Edition
Visual C++ 2008 Express Edition
Visual Web Developer 2008 Express Edition
SQL Server Express Edition

Directlink – 897 MB – DVD Iso File

November 4, 2007

Installing required packages for C compiler on Linux

Filed under: apt-get, c compiler, devoloper, kubuntu, kubuntu 7.10, ubuntu, ubuntu 7.10 — Tags: , , , , — Mustafa Turan @ 11:45 pm

Installing required packages for C compiler on Ubuntu 7.10

If you need to compile C, C++ programs under ubuntu or kubuntu, packages listed below will help you to compile.

apt-get install  libpqxx-dev

apt-get install  libstdc++6-42-doc

apt-get install  cpp-4.2

all packages: gcc, libpqxx-dev, libstdc++6-42-doc,cpp-4.2

Older Posts »

Create a free website or blog at WordPress.com.