<?php
function nrcaracter($str, $char){
return sizeof(explode($char, $str))-1;
}
C++:
#include <iostream>
#include <string>
using namespace std;
int nrdecar(string str, string chr){
int count = 0;
string::size_type start = 0;
while ((start = str.find(chr, start)) != string::npos) {
++count;
start += chr.length();
}
return count;
}
int main(){
string a = "asdfa";
string b = "a";
cout<<nrdecar(a,b);
}