Q:

Removing parenthesized substring from a string located after certain number of characters

I have a task to remove a portion of string from a paragraph of text. The concept is as follows.
1) The portion of string within the parentheses "(" and ")" from the paragraph of text should be removed.
2) Then, do not remove anything if the opening parenthesis is further than 30 characters from the start of the original string.   
Example:
$sample_string = 'Pete Fountain (born Pierre Dewey LaFontaine, Jr., July 3, 1930), is an American, New Orleans based clarinetist. According to a Belgian radio program ("La troisieme oreille", produced by Marc Danval), his name was originally Pierre de la Fontaine.';

$output_string = 'Pete Fountain, is an American, New Orleans based clarinetist. According to a Belgian radio program ("La troisieme oreille", produced by Marc Danval), his name was originally Pierre de la Fontaine.'

Note:
Though the closing parenthesis ")" is beyond 30th character of the string but still the section of string have to be removed. 
Many set of text enclosed within parentheses can appear with in 30th character.

A:

Here is your function, it will also work for parentheses inside another parentheses such as "A string (some more string (some more) some text) ". 
$distance is the number of characters you want opening parenthesis to be away from the beginning (in your case 30) 
function remove($str, $distance) {
$arr = explode('(', $str);
// if first opening paranthesis is not farther away from distance or if there are no 
// parentheses at all, just return the same string 
if (strlen($arr[0]) >= $distance || count($arr) === 1) {
    return $str;
}

// get the position of first character after the first opening parenthesis 
$currentPos = strlen($arr[0])+1;
$open = '(';
$close = ')';
$openCount = 1;

// loop through each character to find the matching closing parenthesis 
while ($currentPos < strlen($str)) {
    $char = substr($str, $currentPos,1);

    // if we find another opening parenthesis, increase the opening parentheses count
    if ($char == $open) {
        $openCount++;
    }

    // if we find a closing parenthesis, decrease openening parentheses count 
    if ($char == $close) {
        $openCount--;
    }
    // when opening parentheses count is zero, that means we found closing parenthesis 
    // position, so now we can remove the substring between opening and closing 
    // parentheses, including the opening and closing parentheses, and return the 
    // result 
    if ($openCount === 0) {
        $parens = substr($str, strlen($arr[0]), $currentPos - strlen($arr[0])+1);
        return str_replace($parens, '', $str);
    }
    $currentPos++;
}

return $str;
}

